Recently started to learn Linux, about the/tmp folder,
The/tmp folder is where the Linux temp files are stored, the files in the/tmp folder in the Linux system are emptied, and how long they are emptied and how they are emptied may not be clear.
In CentOS5.11, you can use the/etc/cron.daily/tmpwatch command to clean the/tmp folder
[Root@localhost ~]# Cat/etc/cron.daily/tmpwatch
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_* ' 240/tmp
/usr/sbin/tmpwatch "$flags" 720/var/tmp
For D In/var/{cache/man,catman}/{cat?,x11r6/cat?,local/cat?}; Todo
If [-D "$d"]; Then
/usr/sbin/tmpwatch "$flags"-F 720 "$d"
Fi
Done
The first line of the script is equivalent to a tag (parameter), the second line is the directory that is excluded from the/tmp directory, the third row, this is the cleanup of this/tmp directory, and the following is the cleanup for other directories.
The files in the/tmp folder in the Linux system are emptied, and how long they are emptied and how they are emptied.
Today we are going to dissect one of these two questions.
In the Rhel\centos\fedora\ system (the experiment was conducted in RHEL6)
Let's take a look at Tmpwatch this command, and 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 for a). The specific use is not much said, interested in their own research. We'll take a look at the scheduled task files related to this command.
It is/etc/cron.daily/tmpwatch, 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
The first line is equivalent to a tag (parameter), the second line is the directory that is excluded from the/tmp directory, the third row, this is the clean up of the/tmp directory, the following is for the other directory cleanup, do not say.
We came to see/usr/sbin/tmpwatch "$flags" 30d/var/tmp this line, the key is this 30d, is 30 days meaning, this determines 30 days to clean/tmp files not accessed. If you want to clean up in a day, change this 30d to 1d.
But there's a problem to be aware of, if you set a shorter time to clean up, for example, 30 minutes, 10 seconds, etc., you can set in this file, but you will find the computer, he does not clean the TMP folder inside the contents, this is why. This is tmpwatch his location, his upper directory is/etc/cron.daily/, and this directory is the first day to perform a scheduled task, so that you set a shorter time than a 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 for experimental environments)
In the Ubuntu system, content in the/tmp folder is emptied every time it is turned on, and if you don't want him to automatically clean up, you just need to change the value of the Tmptime in the RCS file.
We see how to modify
sudo vi/etc/default/rcs
Put
Tmptime=0
Modified into
Tmptime=-1 or Infinity.
This way, the system will not clean your/tmp directory when it is restarted.
And so on, if you want to limit how much time to change, you can change to the corresponding number (I did not test, I understand).
So the conclusion is: in Ubuntu, the system automatically cleans the/tmp folder by default every time it starts.