search
HomeSystem TutorialLINUXThe 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!

Statement
This article is reproduced at:系统家园. If there is any infringement, please contact admin@php.cn delete
Compare and contrast the security models of Linux and Windows.Compare and contrast the security models of Linux and Windows.Apr 24, 2025 am 12:03 AM

The security models of Linux and Windows each have their own advantages. Linux provides flexibility and customizability, enabling security through user permissions, file system permissions, and SELinux/AppArmor. Windows focuses on user-friendliness and relies on WindowsDefender, UAC, firewall and BitLocker to ensure security.

How does hardware compatibility differ between Linux and Windows?How does hardware compatibility differ between Linux and Windows?Apr 23, 2025 am 12:15 AM

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

What are the differences in virtualization support between Linux and Windows?What are the differences in virtualization support between Linux and Windows?Apr 22, 2025 pm 06:09 PM

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

What are the main tasks of a Linux system administrator?What are the main tasks of a Linux system administrator?Apr 19, 2025 am 12:23 AM

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Is it hard to learn Linux?Is it hard to learn Linux?Apr 18, 2025 am 12:23 AM

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

What is the salary of Linux administrator?What is the salary of Linux administrator?Apr 17, 2025 am 12:24 AM

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

What is the main purpose of Linux?What is the main purpose of Linux?Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Does the internet run on Linux?Does the internet run on Linux?Apr 14, 2025 am 12:03 AM

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)