Batch renaming of files (Mac OSX / *nix)

How to batch/bulk rename files with automatic sequence number? Try the following shell script from your terminal (OSX/*nix)

  1. Create a new directory
  2. Run the following command (you can replace newdir with the your directory name and _some_prefix_ with your prefix the same applicable for extension as well. My eg., rename only the png files of the directory (there were no other extensions available).

i=0; for x in *.png; do cp \"$x\" "newdir/some_prefix_$i.png"; i=$(($i+1)); done

Windows should have supported bash scripts natively. OSX is handy only because they inherited from unix.


It doesn’t solve the natural ordering sorting problem eg., File1.png, File10.png, File2.png.

Post Comment