Copying files based on modification date in Linux

Kalai picture Kalai · Aug 12, 2013 · Viewed 79.2k times · Source

I want to copy the last three months' files from one directory to another directory, but I could find only listing the files by using the following command.

find . -mtime -90 -ls

How can I copy the files by using -mtime?

Answer

devnull picture devnull · Aug 12, 2013

Use the -exec option for find:

find . -mtime -90 -exec cp {} targetdir \;

-exec would copy every result returned by find to the specified directory (targetdir in the above example).