Overwrite files on Linux server in multiple directories with a single source

Posted on 2010-01-06
Medium Priority
Last Modified: 2013-12-06
I have a linux web account with SSH access which has multiple accounts contained within it.  I would like to be able to issue a shell command to replace, for example, index.php on in all the subdirectories with a file that I specify.  

Thanks in advance
Question by:robbid

Accepted Solution

vikas_madhusudana earned 1000 total points
ID: 26196957
find <parent dir> -f -name index.php -exec cp -f <sourcefile> {} \;

Assisted Solution

eric-atl earned 1000 total points
ID: 26451221
vikas your syntax looks mostly good, what was the -f switch for in the find it should be in the cp to allow overwrite but you need single quotes around the {} so it should look like this '{}' otherwise bash will try to expand the braces before passing the command to find.  
find <parentDir> -name index.php -exec cp -f <sourceFile> '{}' \;

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating a Samba server for a small office. Ubuntu Linux and Samba can breathe new life into a retired PC and save an office money on new hardware/software. Our example server will have two hard disks, one exclusively for storing shared data. …
This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question