Rename files in Terminal using mv and sed
I want to rename multiple files (in one directory) using mv and sed in Terminal (Mac OS 10.6.8).
I want to change each and every file name from IMG_nnnn.jpg to HVAC_nnnn.jpg, where nnnn is the camera's sequence number. I want to preserve the sequence number and the jpg extension while changing only the file name prefix (the part before the underscore).
Here's what I tried:
macatony-2:HVAC ctossc$ ls -d *.jpg | sed -e 's/.*/mv -f & &/' -e 's/IMG/HVAC/' | sh
This is the result:
mv: rename HVAC_0205.jpg to IMG_0205.jpg: No such file or directory
I wanted "rename IMG_0205.jpg to HVAC_0205.jpg". The arguments to mv seem to be reversed, so the mv command can't "rename" (or delete) the HVAC* file before it is created.
Any suggestions?
macbook, Mac OS X (10.6.7)