2

I would like to remove [] in multiple file names. I get an error when doing it with the rename command.

Is there another way to do this?

2

[] are special characters in Perl Regex syntax which is used by rename command. Use \ in front them. Example:

rename "s/\[|\]/_/g" *

ie:

s replace
[
| or
]
  with
_
* for all files here
1
  • You're a hero. Thank you so much. Works like a charm! – Pramesh Bajracharya Aug 28 '19 at 4:07
0

I prefer to use this command:

for file in $(echo *|grep -E '(\[|\])'); do mv $file $(echo $file|sed -r 's/(\[|\])/_/g'); done

This will replace all square brackets to underscores in the current directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.