A find command in linux cooperates with rm to delete files from a day ago

 

 

Statement writing: find the corresponding directory -mtime + days -name "file name" -exec rm -rf {} \;
Example 1: Delete all files with "." in the /usr/local/backups directory 10 days ago

 

find /usr/local/backups -mtime +10 -name "*.*" -exec rm -rf {} \;


find: Linux search command, the user finds files with specified conditions

/usr/local/backups: any directory you want to clean up

-mtime: Standard statement writing

+10: Find files 10 days ago, where numbers represent the number of days, +30 means to find files 30 days ago

"*.*": The type of data you want to find, "*.jpg" means to find all files with the extension jpg, "*" means to find all files, this can be used flexibly

-exec: fixed spelling

rm -rf: Force deletion of files, including directories

{} \; : Fixed writing, a pair of braces + space + \

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326861752&siteId=291194637