About the Linux System Cleanup/tmp/folder principle

Source: Internet
Author: User
Tags tmp folder

Transferred from: http://www.opsers.org/base/clean-up-on-the-linux-system-tmp-folder-you-may-want-to-know.html

We know that in the Linux system in the/TMP folder inside the file will be emptied, as to how long to be emptied, how to empty, may not have a lot of knowledge, so, today we will analyze one of these two problems.

In the Rhel\centos\fedora\ system (this experiment was conducted in RHEL6)

Take a look at Tmpwatch this command, his role is to delete files that are not used for a period of time (removes files which haven ' t been accessed for a period of the times). The specific usage is not much to say, interested in self-study. We mainly look at the scheduled task files associated with this command.
He's/etc/cron.daily/tmpwatch, and we can look at the contents of this file.
#! /bin/sh
Flags=-umc
/usr/sbin/tmpwatch "$flags"-x/tmp/. X11-unix-x/tmp/. Xim-unix \
-x/tmp/.font-unix-x/tmp/. Ice-unix-x/tmp/. Test-unix \
-X '/tmp/hsperfdata_* ' 10d/tmp
/usr/sbin/tmpwatch "$flags" 30d/var/tmp
For D In/var/{cache/man,catman}/{cat?,x11r6/cat?,local/cat?}; Do
If [-D "$d"]; Then
/usr/sbin/tmpwatch "$flags"-F 30d "$d"
Fi
Done

This script is carefully analyzed to understand that the first line is equivalent to a tag (parameter), the second line is for the/tmp directory in the excluded directory, the third row, this is the/tmp directory cleanup, the following is for the other directory cleanup, do not say.

We just came to see/usr/sbin/tmpwatch "$flags" 30d/var/tmp this line, the key is this 30d, is 30 days meaning, this decided 30 days to clean up the files not accessed by/TMP. If you want to clean up a day, change the 30d to 1d. This you know ... Ha ha!

But there is a problem to note, if you set a shorter time to clean up, say 30 minutes, 10 seconds and so on, you can set in this file, but you will find that re-computer, he does not clean the contents of the/tmp folder, this is why? This is tmpwatch his location, his upper-level directory is/etc/cron.daily/, and this directory is the day to perform a scheduled task, so that you set a shorter time than the day, he will not work. That's clear.
So the conclusion is: in RHEL6, the default time limit for the system to automatically clean the/tmp folder is 30 days.

In the Debian\ubuntu system (Ubuntu10.10 is the experimental environment)

In the Ubuntu system, the contents of the/tmp folder, each boot will be emptied, if you do not want him to automatically clean up, only need to change the RCS file Tmptime value.
Let's see how to Modify
sudo vi/etc/default/rcs
Put
Tmptime=0
Modified into
Tmptime=-1 or infinitely large
In this case, the system will not clean up your/tmp directory when it restarts.
According to some analogy, if you want to limit the amount of time to change, it can be changed to the corresponding number (I did not test, I understand so)

So the conclusion is: in Ubuntu, the system automatically cleans the/tmp folder by default every time it starts

About the Linux System Cleanup/tmp/folder principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.