Skip to content

How to quickly rename multiple files by replacing a specific string in the filename

I found several examples to this here . But I think the simplest method would be to just use the GNU rename utility (see ref link below in the Unix & Linux Stack Exchange)

As a quick example say we had some jpg files that we needed to rename, we can do this like so: rename 's/stringtoreplace/newstring/' *.jpg
The above command would replace all stringtoreplace with newstring.

Unix & Linux Stack Exchange question:
https://unix.stackexchange.com/questions/175135/how-to-rename-multiple-files-by-replacing-string-in-file-name-this-string-conta

To replace # by somethingelse for filenames in the current directory (not recursive) you can use the GNU rename utility:

rename  's/#/somethingelse/' *

Characters like - must be escaped with a \.

For your case, you would want to use

rename 's/#U00a9/safe/g' *

Note that if you only want to operate on a certain selection of files, e.g., only *.jpg, adjust the final input to match that selection:

rename 's/#U00a9/safe/g' *.jpg

To perform a test before actually changing filenames, use the -n flag:

demo/> ls                               
Lucky-#U00a9NBC-125x125.jpg  
Lucky-#U00a9NBC-150x150.jpg 

demo/> rename -n 's/#U00a9/safe/g' *.jpg
rename(Lucky-#U00a9NBC-125x125.jpg, Lucky-safeNBC-125x125.jpg)
rename(Lucky-#U00a9NBC-150x150.jpg, Lucky-safeNBC-150x150.jpg)

For OS X, GNU rename can be installed using homebrewbrew install rename.