How to use Linux to periodically delete expired files using the command

  

During Linux system operation, periodically deleting expired files can free up space memory and avoid waste of resources. You can use commands to implement them. The following small series will introduce you how to use Linux to periodically delete expired commands. file.

code is as follows:

find /var /www /-type f -mtime +30 -exec rm -f & lsquo; {} \\; & rsquo;

The above command deletes expired files older than 30 days.

Command Description:

/var/www/is the path to find files.

-type f is the specified file type as a normal file.

-mtime +30 refers to a file that has been modified for 30 days.

-exec rm -f means to delete the matching files and not prompt, some systems need to take single quotes, and some do not.

Add the above command to the crontab to achieve regular deletion.

For example, delete at 1:30 every day, you can do this:

The code is as follows:

#crontab -e

30 1 * * * Find /var/www/-type f -mtime +30 -exec rm -f ‘{} \\;’

The above is the way to use Linux to periodically delete expired files using commands. At the time, you can choose the time to delete the expired files according to the specific situation. It is the key to choose the period.

Copyright © Windows knowledge All Rights Reserved