One of linux's find commands works with rm to delete a file method from the day before

  • 2020-05-14 05:45:16
  • OfStack

Words: find corresponding directory -mtime + days -name "file name" -exec rm-rf {} \;

Example 1: delete all files in the /usr/local/backups directory with "." 10 days ago

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

find: linux's find command, where the user finds a file with a specified condition

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

-mtime: standard statement writing

+10: find the file 10 days old, where the number represents the number of days, +30 means find the file 30 days old

"*.*" : the type of data you want to find, "*.jpg "for all files with an jpg extension, and "*" for all files

-exec: fixed

rm-rf: forced deletion of files, including directories

{} \; : fixed, 1 pair of braces + space +\

find $1 -name "*.html" -mtime +1 -print0 |xargs -0 rm -v


Related articles: