Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Possible Duplicate:
How can I mass rename files from the command line or using a 3rd party tool?

The title says it all.

The problem is that the first nine files of a couple of hundred are named

1.jpg 2.jpg 3.jpg . . . and so on till..


This screws up the order of the files.

Fixing it manually for a couple of thousand folders could take a long time.

i'm willing to do these one folder at a time if not all at once.

Yet I confess to be ignorant of shell code and programming languages.

Instructions for a batch rename utility will be appreciated.

share|improve this question

marked as duplicate by Ƭᴇcʜιᴇ007, Moab, Nifle, Sathya Aug 16 '11 at 16:36

This question was marked as an exact duplicate of an existing question.

In a POSIX shell (e.g. bash) you can run

for i in *.jpg ; do
    mv $i `printf '%04d' ${i%.jpg}`.jpg

This renames all files X.jpg in the current directory to four digits with prefix zero's. Note that it assumes that all files *.jpg have numbers in their base part only.

share|improve this answer

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