Linux – How to use find to replace several files of the same name

filesfindlinux

I have several files of the same name (say, somefile.php) scattered within several directories under /var/

If I want to replace all of them with a new version of somefile.php located in, say, /home/me/somefile.php … how would I do that? Every search result I find relates to replacing text in a file but I want to replace the entire file.

I know I can find all the files with:

find /var/ -type f -name somefile.php 

But I'm not sure how to move /home/me/somefile.php into the results and replace 'em all.

Best Answer

find /var -type -f -name somefile.php -exec cp /home/me/somefile.php {} \;

be careful!