Linux delete files before the specified date

  
 

If you keep the last 30 days of files in a directory, the files are automatically deleted 30 days ago #find /tmp -mtime +30 -type f -name *.sh[ab] -exec rm -f {} \\; /tmp -- set the directory to look up; -mtime +30 -- set the time to 30 days ago; -type f -- set the type of lookup to file; -name *.sh[ab] -- set the file name to include sha Or shb; -exec rm -f -- delete after the search is completed; Tip: After writing this command to crontab, it can automatically complete the search and delete the work. The other method is similar. #find . -mtime +30 -type f

Copyright © Windows knowledge All Rights Reserved