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 :

#  sudo apt-get install tmpreaper


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,

#  yum install tmpwatch -y
...
Running Transaction
  Installing : tmpwatch-2.9.16-4.el6.x86_64                                                                                                                                                 1/1
  Verifying  : tmpwatch-2.9.16-4.el6.x86_64                                                                                                                                                 1/1
Installed:
  tmpwatch.x86_64 0:2.9.16-4.el6  
...

 tmpwatch Installed Location,
 
# whereis tmpwatch

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,
 
# tmpwatch 30d /tmp/

  all the files that haven’t been accessed for at least 30 days,
 
# tmpwatch --test 60d  ~/download/

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,
 
# tmpwatch  --all 30d  /tmp/

Removing all the files that haven't been accessed for at least 8 hours,
 
tmpwatch --all -mf 8 /tmp

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 --mtime 30 --nodirs /tmp --test

# tmpwatch -am  30 --nodirs /tmp

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