Gilles Ruppert

a.k.a. elduderino78

Batch Rename Files on OSX/Unix

I had to rename a bunch of files in a directory by just changing a prefix. Perfect for the command line, no? After a bit of googling (that exists as a verb now, doesn’t it? :-)) I found this article:Batch File Rename By File Extension in Unix

All you need to do is iterate over all of the files in directory, and then rename by echoing the name & running sed on it, i.e.

for i in *; do mv $i `echo $i | sed 's/search/replace/'`; done

If you need to iterate over a tree of directories or only rename certain files, you can run this command

for f in `find . -type f -name "filename"`; do mv $f `echo $f | sed "s/search/replace/"`; done

If you are using git, you can also exchange mv with git mv.

As always: backups and/or version control are your friends!