Here’s a script that allows you to rename JPG files while adding a counter:

1
2
3
4
5
export j=0 # export is only useful if you're working in interactive mode (not in a script)
for i in *.JPG ; do
    mv $i `echo $i | sed s/^/$j\ -\ /`
    j=$((j+1))
done

Here’s a faster method for renaming files:

Instead of typing:

1
mv my_file.txt my_file.that_i_want_to_backup

You can simply do:

1
mv my_file.{txt,that_i_want_to_backup}

Last updated 05 Aug 2006, 13:09 CEST. history