Replace multiple instances of a file with find

I needed to replace a file that existed in multiple locations on my system with a new copy.

At first I considered a for loop in bash to do it, but then it occurred to me that find would be an ideal fit for this.

To search and replace a file(s) with find, go to the directory you want to search under and use the following command:

find . -name FILENAME -exec cp -f /PATH_AND_NAME_OF_NEWFILE {} \;

That’s it.

This handy little command will search out all instances of FILENAME under your current location and replace them with the new file.

Oh and if  you are using Windows, you can do the same thing with the find included with cygwin.

You ARE running cygwin, aren’t you? If not, then give it a shot. 🙂