Rename every file in a directory to remove part of filename

1

Possible Duplicate:
Mass Rename Files with bash

I have a directory full of files with names like this:

1418450360_72733601001_th-72713048001.jpg?pubId=1418450360
1418450360_72733606001_vs-72703839001.jpg?pubId=1418450360
1418450360_72733607001_th-72703839001.jpg?pubId=1418450360
1418450360_72733618001_vs-72709868001.jpg?pubId=1418450360
1418450360_72733619001_th-72709868001.jpg?pubId=1418450360
1418450360_72733621001_vs-72709874001.jpg?pubId=1418450360
1418450360_72733622001_th-72709874001.jpg?pubId=1418450360
1418450360_72733629001_vs-72714456001.jpg?pubId=1418450360
1418450360_72733630001_th-72714456001.jpg?pubId=1418450360
1418450360_72734162001_vs-72713060001.jpg?pubId=1418450360
1418450360_72734163001_th-72713060001.jpg?pubId=1418450360
1418450360_72734174001_vs-72714480001.jpg?pubId=1418450360
1418450360_72734175001_th-72714480001.jpg?pubId=1418450360
1418450360_72734770001_vs-72718313001.jpg?pubId=1418450360
1418450360_72734771001_th-72718313001.jpg?pubId=1418450360
1418450360_72734776001_vs-72714511001.jpg?pubId=1418450360
1418450360_72734777001_th-72714511001.jpg?pubId=1418450360

What's a quick way of renaming all of them to remove the query part? I.e. from foo.jpg?bar to foo.jpg

Nick Brunt

Posted 2012-10-30T17:16:48.863

Reputation: 672

Question was closed 2012-10-30T20:37:45.793

Answers

5

I have solved it myself:

rename 's/jpg?.*/jpg/' *

Nick Brunt

Posted 2012-10-30T17:16:48.863

Reputation: 672