2

I have many files that look similar to this:

56.mp3?referredby=rss

What I want to do is remove the ?referredby=rss so they'll be like this:

56.mp3

How would I do this?

Proletariat
  • 669
  • 3
  • 16
  • 28

2 Answers2

6

If you have Perl rename, it’s as easy as

rename 's/\?referredby=rss//' ./*referredby=rss

With util-linux rename:

rename '?referredby=rss' '' ./*referredby=rss
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
2

Aside from escaping the ? (which has special meaning in glob expressions) this is really no different from renaming any other files: so for example you could use a simple shell loop

for f in *.mp3\?referredby=rss; do mv -- "$f" "${f%\?*}"; done

where ${f%\?*} is a shell parameter expansion that removes the shortest trailing element matching \?*

steeldriver
  • 78,509
  • 12
  • 109
  • 152