How to Delete Some Files Before a Specified Date in Linux

If you keep files in the last 30 days in a directory, files older than 30 days are automatically deleted
#find /tmp -mtime +30 -type f -name *.sh[ab] -exec rm -f {} ;/tmp –set Search directory;
-mtime +30 - set the time to 30 days ago;
-type f - set the search type to file;
-name *.sh[ab] - set the file name to contain sha or shb;
-exec rm -f – Execute the delete operation after the search is completed;
Tip: After writing this command to crontab, the search and delete can be automatically completed. The
other methods are similar:
#find /tmp -mtime +30 -type f | xargs rm -rf

Guess you like

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