Super User is a question and answer site for computer enthusiasts and power users. 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

I have a bunch of files x1.jpg, x2.jpg, x3.jpg, etc. that need to be named x001.jpg, x002.jpg, x003.jpg, etc. How can I do this?

Edit: I'm running windows but have cygwin installed.

share|improve this question

migrated from Aug 6 '10 at 7:26

This question came from our site for professional and enthusiast programmers.

Should be on However, there's lots of freeware/shareware apps that you can download that does this, just google renamer or similar words. – ho1 Aug 6 '10 at 7:13
Thanks, "renamer" was the keyword I was looking for. – A Person Aug 6 '10 at 7:25

For bulk renaming image files on Windows (as well as resizing, cropping, converting etc.) I often use IrfanView (Freeware)

share|improve this answer

Which OS? *nix has the rename command line utility which seems to be tailored for exactly this kind of thing.

share|improve this answer

A more generic approach than rename (which is not available on all *nix), and potentially allowing quite some creativity:

find . -name 'x*' | while read filename; do mv "$filename" $(echo "$filename" | sed -e 's/x/x00/'); done
share|improve this answer

Cygwin, sweet.

for NEWNUM in $(seq -w 1 100)
    OLDNUM=$(echo $NEWNUM | sed -e 's/^0*//')
    echo $OLDNUM $NEWNUM
    # mv x${OLDNUM}.jpg x${NEWNUM}.jpg

This should work. Well other than the commented out mv. The -w flag to seq means 'wide', meaning begin pad with zeros when necessary

share|improve this answer

Multiple or mass renaming can be called batch renaming.

Total Commander is file manager. It has batch rename feature. You can see tutorial there or there.

Irfan View is image browser/editor. It has batch rename too. You can see tutorial there.

I prefer Total Commander. It has Linux clones and they can probably rename files too.

Both these programs are for Windows. Both should work in Linux too by emulation.

share|improve this answer

In pure bash:

for a in x?.jpg; do mv "$a" "${a/x/x00}"; done
for a in x??.jpg; do mv "$a" "${a/x/x0}"; done
share|improve this answer

You must log in to answer this question.