Really simple batch renaming in Linux
While working on the photos section of trigonakis.com, I wanted to batch rename some photos, so after the renaming their new name would be prefix_i, where i is a incremental value. The following (stupidly) simple bash script provides the desired functionality:
#!/bin/bash INDEX=1 for i in *.$1; do echo item $INDEX: "$i" renamed to $2_$INDEX.$1 mv "$i" $2_$INDEX.$1 let INDEX=INDEX+1 done |
Usage:
#make the script executable chmod +x scriptname.sh #move the folder containing the files to be renamed mv from_path/scriptname.sh to_path/ #run the script ./scriptname.sh FILE_EXTENSION NAME_PREFIX #example: ./rnm.sh JPG photo |