#!/bin/bash # mssrnm: simple script to mass rename files. # This script is quite trivial, so there's no need to cover it with a license. # Just use the code as you see fit. if [[ $1 == "-h" || $1 == "--help" ]]; then echo " This script mass renames files." echo " First parameter is the number of ciphers to be used. Specifying \"5\" will rename the files in the following order: some_pic\$ssuffix => 00000\$esuffix anotheri\$ssuffix => 00001\$esuffix vacation\$ssuffix => 00002\$esuffix speakers\$ssuffix => 00003\$esuffix ... blahblah\$ssuffix => 04798\$esuffix etc. The default is \"3\". \$ssuffix is determined by the second parameter. The default is \".JPG\". \$esuffix is determined by the third parameter. The default is \".jpg\". Example: $ mssrnm 4 .JPG .jpg This will rename all *.JPG files into 0000.jpg, 0001.jpg, 0002.jpg, etc. " exit elif [ ! $1 ]; then glen=3 else glen="$1" fi if [ ! $2 ]; then ssuffix=".JPG" else ssuffix="$2" fi if [ ! $3 ]; then esuffix=".jpg" else esuffix="$3" fi i="0" for file in *"$ssuffix"; do len=${#i} rlen=`expr $glen - $len` name=$i for ((ii=0;ii<$rlen;ii+=1)); do name=0"$name" done name="$name$esuffix" echo "$file => $name" mv "$file" "$name" i=`expr $i + 1` done