Remove the example of an expired cache method using the shell find command

  • 2020-05-27 07:54:09
  • OfStack


Recently, I found that the website has too many cache files, up to 100G, which takes up a large amount of hard disk. However, many cache files are not needed, because the number of times the files are accessed is not the same. Through the search of relevant information found that the most efficient way to save the hard disk cache is to leave only 2 days of cache, because a website file, always be a large number of access to just a few. Here's a look at the detailed solution.

Methods the following

find / -amin -10 #  The lookup is last in the system 10 Minutes to access the file 
find / -atime -2 #  The lookup is last in the system 48 Hours of access to the file 

find / -mmin -5 #  The lookup is last in the system 5 Modified files in minutes 
find / -mtime -1 # The lookup is last in the system 24 Files that have been modified in the last hour 

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

find /backup/logs -mtime -1  Specify a specific directory, 1 It was modified within days. 
find / -mtime +2  Find the one two days ago 

Did you find that +2 is 2 days ago. Minus 2 is within two days.

Find the ones that were interviewed 30 days ago and list them

find /backup/logs -atime +30 -exec ls -l {} \;

Find what was accessed 30 days ago and delete it

find /backup/logs -atime +30 -exec rm -rf {} \;

Meaning, when there are too many cache files, you often need to delete your own cache files to free up space. 1 command, 1 time a day line, so the user access more files, natural left. Those that are not accessed are deleted.


The above is the whole content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.

Related articles: