{"id":610,"date":"2016-06-20T13:54:09","date_gmt":"2016-06-20T08:24:09","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=610"},"modified":"2026-09-07T16:34:18","modified_gmt":"2026-09-07T11:04:18","slug":"using-tmpwatch-to-clear-files-from-tmp-partition","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/using-tmpwatch-to-clear-files-from-tmp-partition\/","title":{"rendered":"Using tmpwatch to clear files from the \/tmp partition"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In a Linux system, services such as Apache and MySQL may create temporary files in the <code>\/tmp<\/code> partition. If the <code>\/tmp<\/code> partition becomes full, it can affect system performance and may cause services to stop or crash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To prevent this, the <code>tmpwatch<\/code> utility can be used to automatically remove old files from <code>\/tmp<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A CentOS\/RHEL-based Linux server<\/li>\n\n\n\n<li>Root or sudo access<\/li>\n\n\n\n<li><code>yum<\/code> package manager<\/li>\n\n\n\n<li>Basic knowledge of Linux commands and cron<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install tmpwatch.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On CentOS, install the <code>tmpwatch<\/code> utility using <code>yum<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">yum -y install tmpwatch<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Clear Old Files from \/tmp<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Execute the following command to clear files from the <code>\/tmp<\/code> partition:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tmpwatch \u2013all -mtime 24 \/tmp<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above command deletes files that are older than <strong>24 hours<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Schedule tmpwatch Using Crontab<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To perform this cleanup periodically, add the command to the crontab:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@daily * * * *  \/usr\/sbin\/tmpwatch \u2013all \u2013mtime 24<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allows the cleanup task to run automatically on a scheduled basis instead of requiring manual execution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>tmpwatch<\/code> utility provides a simple way to remove old temporary files from the <code>\/tmp<\/code> partition. Scheduling the cleanup through cron can help prevent <code>\/tmp<\/code> from becoming full and reduce the risk of services being affected by insufficient temporary storage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1. What is tmpwatch?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>tmpwatch<\/code> is a Linux utility used to remove files that have not been accessed for a specified period of time.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Why should I clean the \/tmp partition?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A full <code>\/tmp<\/code> partition can cause applications and system services to experience errors or fail because they cannot create required temporary files.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. How does <code>-mtime 24<\/code> work?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-mtime 24<\/code> option specifies the age threshold used by the command, allowing old files to be removed based on the configured time period.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Can tmpwatch be scheduled automatically?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can add the <code>tmpwatch<\/code> command to the system&#8217;s crontab so that the cleanup runs automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Downgrade PHP 5.3 to 5.2 in CentOS 6<\/strong> \u2013 Learn how to manage PHP versions on CentOS and configure an older PHP version for legacy application compatibility. <a href=\"https:\/\/pheonixsolutions.com\/blog\/downgrade-php-5-3-to-5-2-in-centos-6\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">Read the article<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How to Configure VNC (Virtual Network Computing) on CentOS<\/strong> \u2013 A practical guide to installing and configuring VNC for remote graphical access to a CentOS server. <a href=\"https:\/\/pheonixsolutions.com\/blog\/configure-vnc-virtual-network-computing-in-centos\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">Read the article<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In a Linux system, services such as Apache and MySQL may create temporary files in the \/tmp partition. If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-610","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-9Q","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=610"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":11459,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/610\/revisions\/11459"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}