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

How can I rename all the files with a pattern like this:



share|improve this question
up vote 7 down vote accepted

Use bash variables and a for loop:
for i in *;do mv $i ${i%0000777};done

when you surround the variable name with {} and add a % sign, it returns the value of the variable with everything after the % removed.

If you use a # sign it will remove from the beginning of the string. so
for i in *;do mv $i ${i#thumb_};done
Would strip the thumb_ off the front.

share|improve this answer

Use the rename script. Assuming that they all end with "0000777":

rename -nv 's,0000777$,,' *

If the output is what you want remove the -n parameter to make it actually rename them.

share|improve this answer
I believe that redhat-type distributions (fedora, etc) have a different rename program that works differently (doesn't support regexes), and you'll have to install separately. – DerfK Oct 23 '12 at 23:41
rename on Debian/Ubuntu systems actually comes as part of perl. It is also know as prename. – Zoredache Oct 23 '12 at 23:49

You don't mention an OS but by the use of your tags I'm going to assume *nix.

However, if you're on Windows regular CMD prompt:

ren *.jpg0000777 *.jpg

or powershell:

Get-ChildItem *.jpg0000777 | Rename-Item -NewName {  $_.Name -replace ".jpg0000777",".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.