Batch renaming files in the form of “prefixNUMBERsuffix”

I finally managed to complete the bash script I wanted to have. I wanted to batch rename files in the form of “prefixNUMBERsuffix”. E.g asd.jpg, dfe.jpg to cats_1.jpg, cats_2.jpg ,etc. And yeah.. that is for my gallery in the blog. So here it goes…

#!/bin/bash 

if (($# != 4));
    then
    echo "Usage: pcrename [prefix] [first_number] [suffix] "[mask]""
    echo "Example: pcrename fun_ 1 .jpg "*.jpg""
else
    prefix=$1
    i=$2
    suffix=$3
    mask=$4

    for fname in $mask
	  do
	  mv "${fname}" "${prefix}${i}${suffix}"
	  ((i++))
	done
fi

P.S My conclusion is that I don’t like bash scripting at all. It hurts my brain!!!

  • Twitter
  • Facebook
  • FriendFeed
  • StumbleUpon
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Tumblr
  • PDF
  • Print
  • email
Rating: (No Ratings Yet)
Loading ... Loading ...
View Comments
Published: May 27th, 2006 (Views: 3)
Categories: Coding
Tags:
blog comments powered by Disqus