


The cleaning principle of /tmp/ folder in Linux system and the role of tmp file
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

The five basic components of Linux are: 1. The kernel, managing hardware resources; 2. The system library, providing functions and services; 3. Shell, the interface for users to interact with the system; 4. The file system, storing and organizing data; 5. Applications, using system resources to implement functions.

Linus Torvalds has released Linux Kernel 6.14 Release Candidate 6 (RC6), reporting no significant issues and keeping the release on track. The most notable change in this update addresses an AMD microcode signing issue, while the rest of the updates

If you're familiar with AirDrop, you know it's a popular feature developed by Apple Inc. that enables seamless file transfer between supported Macintosh computers and iOS devices using Wi-Fi and Bluetooth. However, if you're using Linux and missing o

Keeping your Laptop battery in check is very important for maintaining its longevity and ensuring you're never caught off guard by a sudden shutdown. If you’re a Linux user, you can easily monitor your Laptop's battery level and receive notifications

Linux system management ensures the system stability, efficiency and security through configuration, monitoring and maintenance. 1. Master shell commands such as top and systemctl. 2. Use apt or yum to manage the software package. 3. Write automated scripts to improve efficiency. 4. Common debugging errors such as permission problems. 5. Optimize performance through monitoring tools.

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.
