Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

321
Visualizações
How to run mv command run recursively in Linux

My environment: Bash 3.5 LinuxRedhat

I'm using the following code to rename all of my files in a single directory.

for file in *.* ; do mv "$file" "Add_$file" ; done

Now, I want to rename my file recursively.And I don't know how to do.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The first ideas with find don't work, because {} returns ./ with the command:

find . -type f -name "*.*" -execdir mv {} Add_{} ";"

We need something, which removes the ./ in front but works in subdirectories too.

echo 'f=$(basename "$1"); mv "$f" Add_"$f";' > adhoc.sh
chmod a+x adhoc.sh
find . -type f -name "*.*" -execdir $PWD/adhoc.sh "{}" ";"

At least this works for gnu-find. Other finds might not have an -execdir command.

Thanks for skyking for pointing my error out.

For Linux, you might find a version of 'rename' in the repository, but normally it has to be installed and isn't part of the standard installation. If you often rename with the commandline, it is worth the effort. With rename, you specify a regex substitute command and can test it first:

find . -type f -exec rename -n "s/(.*)/Add_\1/" {} ";" 
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda