Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying files based on modification date in Linux

Tags:

linux

bash

cp

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?

like image 486
Kalai Avatar asked Sep 01 '25 22:09

Kalai


1 Answers

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

like image 97
devnull Avatar answered Sep 03 '25 13:09

devnull