#!/bin/sh # ren.sh # Use this script to rename a group of .jpg files to new names sequentially. # # Parameters # - New file name prefix. For example, to rename a group of files # Vacation1.jpg, Vacation2.jpg, etc, pass the first parm as Vacation # - Files to rename (Up to 9 I think) if [ $# -lt 2 ] ; then echo "Usage: ren.sh FilePrefix File1.jpg File2.jpg ..." exit fi # Set initial number to 0 num=0 # Loop through all parameters passed to script for i in $* do # First parameter is the prefix. if [ $num -eq 0 ] ; then prefix_name=$i; else # Remaining parameters are the original file names # Check if the new file name already exists. Keep incrementing the # counter until we find a name that is not already in use. exists="Y" while [ $exists = "Y" ] do if [ $num -lt 10 ] ; then new_file=$prefix_name"0"$num.jpg else new_file=$prefix_name$num.jpg fi if [ -f $new_file ] ; then num=`expr $num + 1` else exists="N" fi done # Rename the file mv $i $new_file fi num=`expr $num + 1` done