{"id":6467,"date":"2017-02-11T00:09:06","date_gmt":"2017-02-10T16:09:06","guid":{"rendered":"http:\/\/rmohan.com\/?p=6467"},"modified":"2017-02-11T00:09:06","modified_gmt":"2017-02-10T16:09:06","slug":"how-to-use-tmpwatch-command-in-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6467","title":{"rendered":"How to use tmpwatch Command in Linux"},"content":{"rendered":"<p><strong>How to Install tmpwatch CentoOS\/Fedora\/RHCE :<\/strong><\/p>\n<p>By default, this package not being installed in Linux (VPS) so that we can install using yum command,<\/p>\n<div><strong>#\u00a0 yum install tmpwatch -y<\/strong><br \/>\n&#8230;<br \/>\nRunning Transaction<br \/>\nInstalling : tmpwatch-2.9.16-4.el6.x86_64\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\/1<br \/>\nVerifying\u00a0 : tmpwatch-2.9.16-4.el6.x86_64\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\/1<br \/>\nInstalled:<br \/>\ntmpwatch.x86_64 0:2.9.16-4.el6<br \/>\n&#8230;<\/div>\n<p>tmpwatch Installed Location,<\/p>\n<div># whereis tmpwatch<\/p>\n<p>tmpwatch: \/usr\/bin\/tmpwatch \/usr\/sbin\/tmpwatch \/usr\/share\/man\/man8\/tmpwatch.8.gz<\/p><\/div>\n<p><strong>How to cleanup \/tmp directory files that haven\u2019t been accessed for at least 30 days,<\/strong><\/p>\n<div># tmpwatch 30d \/tmp\/<\/div>\n<p><strong>\u00a0 all the files that haven\u2019t been accessed for at least 30 days,<\/strong><\/p>\n<div># tmpwatch &#8211;test 60d\u00a0 ~\/download\/<\/p>\n<p>removing file \/root\/download\/tmpwatch_1<br \/>\nremoving file \/root\/download\/tmpwatch_2<br \/>\nremoving file \/root\/download\/tmpwatch_3<br \/>\nremoving file \/root\/download\/tmpwatch_4<\/p><\/div>\n<p><strong>Removing all the files that haven\u2019t been accessed for at least 30 days,<\/strong><\/p>\n<div># tmpwatch\u00a0 &#8211;all 30d\u00a0 \/tmp\/<\/div>\n<p><strong>Removing all the files that haven&#8217;t been accessed for at least 8 hours,<\/strong><\/p>\n<div>tmpwatch &#8211;all -mf 8 \/tmp<\/div>\n<p><strong>Remove all the files except directories even if they are empty.<\/strong><\/p>\n<p>First command is do not delete but listing out what would be deleted and the second command is delete all the files only\u00a0 that haven\u2019t been accessed for at least 30 hours,<\/p>\n<div># tmpwatch &#8211;mtime 30 &#8211;nodirs \/tmp &#8211;test<\/p>\n<p># tmpwatch -am\u00a0 30 &#8211;nodirs \/tmp<\/p><\/div>\n<p><strong>Schedule Cron Job every 5 Hours<\/strong><\/p>\n<div>\n<div id=\"highlighter_524753\" class=\"syntaxhighlighter  shell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"shell plain\">0\u00a0 *<\/code><code class=\"shell plain\">\/5<\/code>\u00a0 <code class=\"shell plain\">*\u00a0\u00a0 *\u00a0\u00a0 *\u00a0\u00a0 <\/code><code class=\"shell plain\">\/usr\/bin\/tmpwatch<\/code>\u00a0\u00a0 <code class=\"shell plain\">-am\u00a0 30\u00a0 --nodirs <\/code><code class=\"shell plain\">\/tmp<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>-d (or) &#8211;nodirs\u00a0\u00a0\u00a0\u00a0 Do not attempt to remove directories, even if they are empty.<\/p>\n<p>-m (or) &#8211;mtime\u00a0 \u00a0\u00a0 Deleting\u00a0 files based on\u00a0 modification time<\/p>\n<p>-a,(or)\u00a0 &#8211;all \u00a0 \u00a0\u00a0 \u00a0 \u00a0\u00a0 Remove all file types<\/p>\n<p>-t (or)\u00a0 &#8211;test \u00a0 \u00a0 \u00a0 \u00a0 Don&#8217;t remove files, displaying what would be deleted<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Install tmpwatch CentoOS\/Fedora\/RHCE :<\/p>\n<p>By default, this package not being installed in Linux (VPS) so that we can install using yum command,<\/p>\n<p> # yum install tmpwatch -y &#8230; 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 &#8230; <\/p>\n<p>tmpwatch Installed Location,<\/p>\n<p> # whereis tmpwatch<\/p>\n<p>tmpwatch: \/usr\/bin\/tmpwatch \/usr\/sbin\/tmpwatch \/usr\/share\/man\/man8\/tmpwatch.8.gz<\/p>\n<p>How [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6467"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6467"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6467\/revisions"}],"predecessor-version":[{"id":6468,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6467\/revisions\/6468"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}