Tmpwatch tool is analyze and recursively delete files which have not been used certain period of time, especially clean up unwanted backup or /tmp directory or unused files.
How to Install tmpwatch Ubuntu :
How to Install tmpwatch CentoOS/Fedora/RHCE :
By default, this package not being installed in Linux (VPS) so that we can install using yum command,
Installing : tmpwatch-2.9.16-4.el6.x86_64 1/1
Verifying : tmpwatch-2.9.16-4.el6.x86_64 1/1
tmpwatch Installed Location,
tmpwatch: /usr/bin/tmpwatch /usr/sbin/tmpwatch /usr/share/man/man8/tmpwatch.8.gz
How to cleanup /tmp directory files that haven’t been accessed for at least 30 days,
all the files that haven’t been accessed for at least 30 days,
removing file /root/download/tmpwatch_1
removing file /root/download/tmpwatch_2
removing file /root/download/tmpwatch_3
removing file /root/download/tmpwatch_4
Removing all the files that haven’t been accessed for at least 30 days,
Removing all the files that haven’t been accessed for at least 8 hours,
Remove all the files except directories even if they are empty.
First command is do not delete but listing out what would be deleted and the second command is delete all the files only that haven’t been accessed for at least 30 hours,
# tmpwatch -am 30 –nodirs /tmp
Schedule Cron Job every 5 Hours
-d (or) –nodirs Do not attempt to remove directories, even if they are empty.
-m (or) –mtime Deleting files based on modification time
-a,(or) –all Remove all file types
-t (or) –test Don’t remove files, displaying what would be deleted