Bash: Rename all files inside current directory

Renaming all files inside a directory can be done with the following code.

find * -type f | while read FILE; do mv "$FILE" old_"$FILE"; done;

The code will take all filenames in the current directory, and append "old_" to the name.

find * -type f
- Will make a list of all files in the current directory.
while read FILE; do ...; done
- Will read from a list each line into the variable FILE.
mv "$FILE" old_"$FILE";
- Will rename the filename in the variable $FILE to old_$FILE. Check out the double quotes - they are important, otherwise filenames with spaces will break the move command.

Related posts:


 
 
 

Die Kommentarfunktion zu diesem Beitrag wurde deaktiviert.