-1

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

3 Answers 3

7

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.

3

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.

2
  • 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, 2012 at 23:41
  • rename on Debian/Ubuntu systems actually comes as part of perl. It is also know as prename.
    – Zoredache
    Oct 23, 2012 at 23:49
2

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"  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .