Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda