X system cleanup/tmp/folder Principle

Source: Internet
Author: User
Tags tmp folder

Transferred from: bytes §

We know that in Linux, files in the/tmp folder will be cleared. As to how long the files will be cleared and how to clear the files, there may not be much knowledge, today, we will analyze these two problems.

In the RHEL \ centos \ fedora \ System (this experiment was conducted in rhel6)

Let's take a look at the tmpwatch command. Its function is to delete files that are not used for a period of time (removes files which haven' t been accessed for a period of time ). I will not talk about the specific usage. If you are interested, study it on your own. We mainly look at the scheduler task files related to this command.
This is/etc/cron. daily/tmpwatch. Let's take a look at the content in 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 analyzed carefully to understand that the first line is equivalent to a tag (parameter), the second line is for the Directory excluded from the/tmp directory, and the third line, this is to clean up the/tmp directory. The following is to clean up other directories.

Let's take a look at the/usr/sbin/tmpwatch "$ flags" 30d/var/tmp line. The key is this 30d, which means 30 days, it takes 30 days to clear files that are not accessible under/tmp. If you want to clean up a day, change the 30d to 1D. You know this ...... Haha!

Note that if you set a shorter time to clean up, for example, 30 minutes or 10 seconds, you can set it in this file, but you will find that the computer does not clean up the content in the/tmp folder. Why? This is determined by the position of tmpwatch. Its upper directory is/etc/cron. daily/, and this directory is the first day to execute a scheduled task. Therefore, if you set a shorter time than a day, it will not work. Now I understand.
Therefore, in rhel6, the default time for the/tmp folder to be automatically cleared is 30 days.

In the Debian \ Ubuntu System (ubuntu10.10 is the experimental environment)

In ubuntu, the content in the/tmp folder is cleared every time it is started. If you do not want it to be cleared automatically, you only need to change the tmptime value in the rfm file.
Let's see how to modify it.
Sudovi/etc/default/RCS
Set
Tmptime = 0
Modify
Tmptime =-1 or infinitely large
In this case, the system will not clear your/tmp directory during restart.
And so on, if you want to change the time limit, you can change it to the corresponding number (I didn't test it, so I understand it)

So the conclusion is: In ubuntu, the time limit for the system to automatically clean the/tmp folder is set to start each time by default.


X 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.