Thursday, 6 February 2014

Renaming multiple files

Have you got a folder full of files that you want to rename in the same way? If you are using Linux or Mac you can do it with one line of commands.

I had a folder of images named 1.png, 2.png etc. and I wanted to rename them all to Date_Event_1.png, Date_Event_2.png etc.

Open a command line - Terminal on your Mac and navigate to the folder containing the files you wish to rename and type the following command:

for filename in *.png; do mv "$filename" "Date_Event_$filename"; done;

And just in case you want to revert back:
for filename in *.png; do mv $filename `echo $filename | sed 's/\Date_Event_//'`; done;

Note the two different apostrophes in that last command.