Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I bulk rename multiple files named

Image401.jpg, Image402.jpg,...


Image 001.jpg, Image002.jpg, ... ?

share|improve this question
up vote 1 down vote accepted

You just want to change '4' to '0'?

for f in Image4*.jpg
  # replace Image4 prefix with Image0
  mv "$f" "$newname"

Or you want to subtract 400 from the numeric part? Or something else?

share|improve this answer
mv "$f" Image0"${f#Image4}" is a much faster and safer way to do this. The $( echo | sed ) approach, even if it works on filenames like Image401.jpg, is not very robust as it will mangle filenames containing odd characters or spaces, and is much slower because of the extra temporary subshell and processes created for every single file. – jw013 Mar 12 '12 at 18:44
All true - and it wasn't even the best sed command to use. – Useless Mar 12 '12 at 18:59

Under Linux, to change the first 4 in the file names to 0:

rename 4 0 Image4*.jpg

Under Debian, Ubuntu and derivatives, rename is a different file renaming program, which is based on a Perl expression. Either call rename.ul instead, or call the Perl renaming script:

rename 's/4/0/' Image4*.jpg
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.