Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

thumb_f318d8a580ca5717d686a323b6c2ca0d.jpg0000777
thumb_f18d8aup90ca5717d686a323b6c2c5uh.jpg0000777
thumb_jessr8d8a580ca5717d68623etrtckks.jpg0000777
thumb_4hghd8a580ca5717d686a323b6c2ghjj.jpg0000777
....

to

thumb_f318d8a580ca5717d686a323b6c2ca0d.jpg
thumb_f18d8aup90ca5717d686a323b6c2c5uh.jpg
thumb_jer8d8a580ca5717d686a323etrtckks.jpg
thumb_4hghd8a580ca5717d686a323b6c2ghjj.jpg
....
share|improve this question

3 Answers 3

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

 
discard

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.