In linux shell, How to cp/rm files by time? In linux shell, How to cp/rm files by time? shell shell

In linux shell, How to cp/rm files by time?


Depending on what you actually want to do, find provides -[acm]time options for finding files by accessed, created or modified dates, along with -newer and -min. You can combine them with -exec to copy, delete, or whatever you want to do. For example:

find -maxdepth 1 -mtime +1 -type f -exec cp '{}' backup \;

Will copy all the regular files in the current directory more than 1 day old to the directory backup (assuming the directory backup exists).


Simple Example

find /path/to/folder/ -mtime 1 -exec rm {} \; // Deletes all Files modified yesterday

For more examples google for bash find time or take a look here