May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

How to use tmpwatch Command in Linux

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

1
2
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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>