Showing posts with label batch rename file bash linux. Show all posts
Showing posts with label batch rename file bash linux. Show all posts

Wednesday, July 09, 2008

Bash script for renaming files en masse


#! /bin/bash
x=0
for i in `ls $1/*.$2`
do
mv $i `printf "%03x.$2" $x`
x=$(($x+1))
done



Usage : (say call the script a.sh )
./a.sh /var/www/html/images jpeg
will sequentially rename all jpeg files in /var/www/html/images to 001.jpeg 002.jpeg etc.