Search code examples
linuxbashcp

Copying files based on modification date in Linux


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?


Solution

  • 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).