How to use tmpwatch Command in Linux
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,
tmpwatch Installed Location,
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 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,
Schedule Cron Job every 5 Hours
0 */5 * * * /usr/bin/tmpwatch -am 30 --nodirs /tmp
-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