1

I have a lot of files in a directory that have [!] in the file name. Is there a way to trim that out with a command in the terminal? Here's an example filename. file001[!].ext

  • you want to remove a specific character in file name? – Ruskes Mar 8 '15 at 22:48
  • character's'. Specifically, the one's I mentioned. [!] – Frantumn Mar 8 '15 at 23:07
2

I would just use the 'sed' command. You can run a for each loop over all the files and parse out the "[!]".

sed 's/\[!]//'

for loop version:

for f in /path/to/files/*; do
rename=`echo "$f" | sed 's/\[!]//'`
mv "$f" "$rename"
done

Otherwise I would suggest installing "rename" from homebrew if you have that installed. I also have a Automator right click service that does batch rename's if you would like a graphical way.

  • I'd add an if statement before mv to preserve timestamps for files that do not need to be renamed. – Mateusz Szlosek Mar 9 '15 at 13:47
2

Yosemite features a graphical way to do this. Select all the files you want to rename, Control-click on them, select "Rename x Items...", and you'll get what is basically a find-and-replace window for file names.

enter image description here


In your case, select "Replace text" and substitute "[!]" with the empty string.

enter image description here

  • 1
    Got to say did not know about. Nice one – markhunte Mar 9 '15 at 22:12

You must log in to answer this question.

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