In linux shell, how are cp / rm files by time?

In linux shell when I run

ls -al -t

which show the time of files.

How to cp / rm files in time? as well as copying all files created today or yesterday. Many thanks.

+5
source share
2 answers

Simple example

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

More google examples for bash find the time or look here

+7
source

Depending on what you really want to do, it findprovides options -[acm]timefor finding files by available, created or modified dates along with -newerand -min. You can combine them with -execto copy, delete, or whatever you want to do. For instance:

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

1 backup (, backup).

+8

All Articles