Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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..

9.jpg

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 has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

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

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

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.