Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 php.info -exec cp -f  /var/somefile.php {}

or?

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

1 Answer 1

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"
    done

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

 
discard

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.