Home > System Tutorial > LINUX > The cleaning principle of /tmp/ folder in Linux system and the role of tmp file

The cleaning principle of /tmp/ folder in Linux system and the role of tmp file

WBOY
Release: 2023-12-21 17:36:17
forward
2991 people have browsed it

Most of the

.tmp files are files left behind due to abnormal shutdown or crash. These temporary scratch disks have no use after you restart the computer, so you can safely delete them. When you use the Windows operating system, you may often find some files with the suffix TMP in the root directory of the C drive, and you will also find a TEMP directory in the Windows directory. TMP files are temporary files generated by various software or systems. , also known as junk files. Temporary files generated by Windows are essentially the same as virtual memory, except that temporary files are more targeted than virtual memory and only serve a certain program. Its specificity has caused many novices to be intimidated by it. If it is not deleted, it will occupy space, and if it is deleted, it will cause the program to fail to run.

After years of using Windows, there will definitely be a lot of "junk" in Windows\Temp. In fact, all files or folders in this Temp can be deleted, so you might as well do it when you have time. Clean up the Temp folder frequently, but please note that I am referring to deleting the things in Temp (the Temp folder is still retained), not deleting the entire Temp folder together. When you delete files in Temp, you may encounter an "Access Denied" error message. It doesn't matter, this is normal.

Because some of them are current temporary disks and are still in use by Windows, you can skip the files with access denial messages and continue to delete other files. Generally speaking, When you are currently running large tool software, you should not touch temporary files. For example, Photoshop will generate huge temporary files when processing graphics. If you think this is not a file created by you and you try to delete it, it may cause Photoshop to crash. If you are not currently running a program, you can delete all the temporary files you find to prevent them from piling up over time and occupying disk space. The key is that they are numerous and scattered, which will cause unnecessary waste of time in disk scanning and sorting, and may It will cause confusion in the file allocation table and lead to file cross-link errors. But not all temporary files can be lumped together. For example, the TEMP directory in the root directory of drive C is the pointing directory for temporary files of many tool programs. Without this directory, temporary files cannot be created, and these tool software are likely to cause errors. Therefore, if you want to delete them, you should only clear the temporary files inside. It is not recommended to delete all the files in the TEMP directory; there is usually a TEMP file in Windows, which is the default place for temporary files in the system. It is not recommended to delete even the directory, and just clear out the garbage in it regularly.

About the principle of cleaning the /tmp/folder in the Linux system

We know that the files in the /tmp folder will be cleared in the Linux system. As for how long it will take to be cleared, and how to clear it. Yes, maybe you don’t know much about it.

In the RHEL\CentOS\Fedora\ system (this experiment was conducted in RHEL6)

Let’s take a look at the tmpwatch command first. Its function is to delete the command if it is not used for a period of time. (removes files which haven't been accessed for a period of time). I won’t go into details on how to use it. If you are interested, you can research it yourself. We mainly look at the scheduled task files related to this command.

He is /etc/cron.daily/tmpwatch, we can take a 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

If you analyze this script carefully, you will understand. The first line is equivalent to a mark (parameter), the second line is for the excluded directories in the /tmp directory, and the third line is for this The cleaning of the /tmp directory, the following is for the cleaning of other directories, so I won’t go into details.

Let’s take a look at the line /usr/sbin/tmpwatch "$flags" 30d /var/tmp. The key is this 30d, which means 30 days. This is the decision. Clean up inaccessible files in /tmp for 30 days. If you want to clean up once a day, change this 30d to 1d.

But there is a problem to note. If you set a shorter time to clean up, such as 30 minutes, 10 seconds, etc., you can set it in this file, but You will find that when you restart the computer, it does not clean up the contents of the /tmp folder. Why is this? This is determined by the location of tmpwatch. Its upper directory is /etc/cron.daily/, and this directory executes a scheduled task every day. Therefore, if you set a time shorter than one day, it will not It worked. Now you understand.

So the conclusion is: in RHEL6, the default time limit for the system to automatically clean up the /tmp folder is 30 days

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

In the Ubuntu system, the contents of the /tmp folder will be cleared every time the computer is turned on. If you do not want it to be automatically cleaned up, you only need to change the value of TMPTIME in the rcS file.

Let’s see how to modify it

sudo vi /etc/default/rcS

Change

TMPTIME=0

to

TMPTIME=-1 or infinite

If you change it to this, the system will not clean up your /tmp directory when it restarts.

By analogy, if you want to limit the time to change, you can change it to the corresponding number (I have not tested it, this is my understanding)

So the conclusion is: In Ubuntu, the time limit for the system to automatically clean up the /tmp folder defaults to every startup

The above is the detailed content of The cleaning principle of /tmp/ folder in Linux system and the role of tmp file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
tmp
source:somode.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template