Tuesday 10 June 2008

Renaming multiple files with 'rename' command

The syntax for the rename command is:

rename [ -v ] [ -n ] [ -f ] perl_expression [ files ]

to rename for example multiple photo files with '.JPG' extension to '.jpg' extension:

rename -v ’s/\.JPG$/\.jpg/’ *.JPG

The perl substitution for regular expression syntax is: s/old/new/.
s means 'substitute'. Period character substitutes any character, but in this case it's not wanted and we need to escape it with '\'.

No comments: