Server Fault is a question and answer site for system and network administrators. 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

What am I missing here, this seems so simple yet I cant get it to work.

I have a directory with files like AGPNDRAH01.jpg

I want a directory with files like AGPNDRAH01_00.jpg

rename 's/(\w+).jpg\$1\_00.jpg$//' *

Doesnt, work. Centos linux. Makes no sense to me why this isnt working.

share|improve this question
up vote 4 down vote accepted

Quick hack that will do what you describe in bash:

cd /directory
for F in `ls -1 |awk -F. '{print $2}'`
  mv $F.jpg ${F}_00.jpg

For rename usage:

wmoore@bitbucket(/tmp/dowork)$ ls -1
wmoore@bitbucket(/tmp/dowork)$ rename .jpg _00.jpg *.jpg
wmoore@bitbucket(/tmp/dowork)$ ls -1
share|improve this answer
This worked, but i'm really curious why rename isnt working. – Mech Software Mar 24 '10 at 18:39
let's suppose the name of the picture has a "." in it before the .jpg :) – Jimmy Mar 24 '10 at 18:42
That did it you man page must be better equipped than mine. rename .jpg _00.jpg *.jpg did it. Thanks! – Mech Software Mar 24 '10 at 18:44
Then I'd suppose you'd be using a non-standard naming convention that my systems wouldn't employ, Marcel. ;) – Warner Mar 24 '10 at 18:48

Try the following bash script:

find . -type f -name "*.jpg" -print | while read FILE  
  do mv "${FILE}" "`dirname ${FILE}`/`basename ${FILE} .jpg`_00.jpg"

That will find all .jpg files in or below the current directory and insert _00 before .jpg. If you only want it to handle the current directory start the find command with find . -maxdepth 1

share|improve this answer

I am not familiar with rename, but your regex doesn't look right. It appears like you are trying to match files named like this AGPNDRAH01.jpg.AGPNDRAH01_00.jpg and change their name to nothing.

Are you sure you don't mean something like this instead?

rename 's/(\w+).jpg$/\$1\_00.jpg/' *
share|improve this answer
I tried a variant of that, and I tried what you have listed there. Didnt work either. – Mech Software Mar 24 '10 at 18:36

I have a variant of redhat, and rename doesn't support the 's/' command. Here's a one-liner for you (You have to backslash parenthesis and plus-signs to get the functionality in sed):

for fl in *.jpg; do mv $fl `echo $fl | sed 's/\(\w\+\).jpg/\1_00.jpg/'`; done
share|improve this answer

You just had a slash in the wrong place and an unnecessary backslash.

rename 's/(\w+).jpg/$1\_00.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.