Jump to Navigation

158 - Clean up /tmp directory

If you are a Linux administrator, then you certainly need a tool to delete old files - especially old backup files or /tmp directory.
Here comes tmpwatch. With parameter time and path, tmpwatch will recursively delete all files older then a given time.

To clean up /tmp directory by crontab :

   0 */2 * * * /usr/sbin/tmpwatch -maf 8 /tmp 

   0 5 * * * /usr/sbin/tmpwatch -md 24 /tmp 

   0 5 * * * /usr/sbin/tmpwatch -maf 24 -x /tmp/lost+found /tmp 

This crontab entry will delete all files from the /tmp directory older than 8 hours. Cron will run tmpwatch every two hours.
Parameters for the tmpwatch are:

    * m - make decision on last modification time instead of access time.
    * d - Do not remove directories.
    * a - remove all file types, not just regular files, symbolic links and directories
    * f - Force removal of read-only files (similar to rm -f)
    * x - Skip the specified path, the absolute path of a directory or file.

 

 

Linux:


Main menu 2

Story | by Dr. Radut