1

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

Thor
  • 475
  • 5
  • 14
user206691
  • 11
  • 1

1 Answers1

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.