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. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: