Skip to main content

remove asterisk from filename [Resolved]

I have a bunch of filenames that look like this:

2501254200*.nc

I want to remove the asterisk. But when I use the following code:

mmv '***' '#1#2' 

I get the error

2501254200*.nc -> : bad new name

Nothing done

How do I remove the * from the name?


Question Credit: Jellyse
Question Reference
Asked July 18, 2019
Tags: rename
Posted Under: Unix Linux
9 views
2 Answers

I don't use mmv much, but here it looks like you need the middle * to exactly match the * character in the filename. Since * is otherwise a pattern, try escaping the middle *:

mmv '*\**' '#1#2' 

credit: muru
Answered July 18, 2019

You need to escape the * which you want to use literally. Try this:

for file in *\**; do  mv "$file" "${file/\*/}"; done

Or, if you have perl-rename (installed as rename on Debian and its derivatives like Ubuntu):

rename 's/\*//' *

credit: terdon
Answered July 18, 2019
Your Answer