Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to find and replace certain string through files, but I'm interested how could I find and replace whole files? e.g. I would like to find all info.php files that were modified at specific time and replace them with another file.

Something like:

find -f /home/ -name -exec cp -f  /var/somefile.php {}


I'm not sure how to add so it will only search for files that were modified, e.g., at 20.1.2014

share|improve this question

find has an -mtime filter you can use for that.

For more elaborate search-and-replace, you can also use a shell loop.

    find WHATEVER | while read f ; do
       ## add your own test here, like …
       # fgrep -qs "do not delete" "$f" && continue
       cp -f /what/ever "$f"

For supplying find with exact dates, use something along the lines of -newermt 2014-01-20 \! -newermt 2014-01-21.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.