{"id":871,"date":"2020-05-31T14:14:17","date_gmt":"2020-05-31T08:14:17","guid":{"rendered":"https:\/\/hasibul.info\/blog\/?p=871"},"modified":"2020-05-31T14:14:17","modified_gmt":"2020-05-31T08:14:17","slug":"how-to-clean-tmp-directory-automatically-in-linux-cpanel-using-tmpwatch","status":"publish","type":"post","link":"https:\/\/hasibul.info\/blog\/2020\/05\/31\/how-to-clean-tmp-directory-automatically-in-linux-cpanel-using-tmpwatch\/","title":{"rendered":"How to clean \/tmp directory automatically in Linux\/cPanel using tmpwatch"},"content":{"rendered":"<p>The \u201ctmpwatch \u201d command in linux is to removes files which haven&#8217;t been accessed for a period of time. The tmpwatch recursively removes files which haven&#8217;t been accessed for a given time. Normally, it&#8217;s used to clean up directories which are used for temporary holding space such as \/tmp.<\/p>\n<p>If you are noticing &#8220;\/tmp&#8221; getting overloaded with files and not sure which files\/folders to delete &#8211; you better use &#8220;tmpwatch&#8221; to cleanup or delete files\/folders from the &#8220;\/tmp&#8221; directory.<\/p>\n<p>You&#8217;ll need SSH root access to install tmpwatch and add it in the cron. If your server is inaccessible due to &#8220;\/tmp&#8221; getting full &#8211; you may restart the server and that should free up some space after reboot.<\/p>\n<ol>\n<li>Login to the server as root using SSH<\/li>\n<li>Run the following command:<br \/>\n<blockquote><p>#yum install tmpwatch -y<\/p><\/blockquote>\n<\/li>\n<li>To delete temporary files (for example after every 12 hours) run the following command:<br \/>\n<blockquote><p>#\/usr\/sbin\/tmpwatch -am 12 \/tmp<\/p><\/blockquote>\n<\/li>\n<li>The next step is to configure tmpwatch to run automatically through a cron. To do that type the following command:<br \/>\n<blockquote><p>#crontab -e<\/p><\/blockquote>\n<\/li>\n<li>The above command will open the cron job list for the user root. Now go to the bottom and add the following line and save the file:<br \/>\n<blockquote><p>0 4 * * * \/usr\/sbin\/tmpwatch -am 12 \/tmp<\/p><\/blockquote>\n<p>If you are unable to add the above line, you may navigate to &#8220;\/var\/spool\/cron&#8221; and open the cron file &#8220;root&#8221; with a text editor (such as, vi, nano). Add the line at the bottom and save the file:<\/p>\n<blockquote><p>0 4 * * * \/usr\/sbin\/tmpwatch -am 12 \/tmp<\/p><\/blockquote>\n<\/li>\n<\/ol>\n<p>Check the usage of &#8220;\/tmp&#8221; and it should be clean by now.<\/p>\n<p>Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The \u201ctmpwatch \u201d command in linux is to removes files which haven't been accessed for a period of time. The tmpwatch recursively removes files which haven't been accessed for a given time. Normally, it's used to clean up directories which are used for temporary holding space such as \/tmp. If you are noticing \"\/tmp\" getting&hellip;<\/p>","protected":false},"author":1,"featured_media":872,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,18,6,12],"tags":[109,96,124,95,97,283,260,420],"how-to":[],"_links":{"self":[{"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/posts\/871"}],"collection":[{"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/comments?post=871"}],"version-history":[{"count":0,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/posts\/871\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/media\/872"}],"wp:attachment":[{"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/media?parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/categories?post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/tags?post=871"},{"taxonomy":"how-to","embeddable":true,"href":"https:\/\/hasibul.info\/blog\/wp-json\/wp\/v2\/how-to?post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}