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

Posted on 2010-01-06
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
    LVL 7

    Accepted Solution

    find <parent dir> -f -name index.php -exec cp -f <sourcefile> {} \;
    LVL 4

    Assisted Solution

    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

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    E-mail settings for Fail2ban 7 89
    Linux Contiguous File 34 142
    ovirt web management page 1 57
    linux 2 62
    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…
    If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now