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

Dec 21, 2023 pm 05:36 PM
tmp

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Mastering Text Manipulation With the Sed Command Mastering Text Manipulation With the Sed Command Mar 16, 2025 am 09:48 AM

The Linux command line interface provides a wealth of text processing tools, one of the most powerful tools is the sed command. sed is the abbreviation of Stream EDitor, a multi-functional tool that allows complex processing of text files and streams. What is Sed? sed is a non-interactive text editor that operates on pipeline inputs or text files. By providing directives, you can let it modify and process text in a file or stream. The most common use cases of sed include selecting text, replacing text, modifying original files, adding lines to text, or removing lines from text. It can be used from the command line in Bash and other command line shells. Sed command syntax sed

Pilet: A Modular, Portable Mini-Computer Powered by Raspberry Pi Pilet: A Modular, Portable Mini-Computer Powered by Raspberry Pi Mar 06, 2025 am 10:11 AM

Discover Pilet: A Retro-Futuristic, Open-Source Mini-Computer Looking for a mini-computer that blends classic style with cutting-edge technology? Meet Pilet, a modular, open-source marvel powered by the Raspberry Pi 5. Boasting a 7-hour battery life

Linux Kernel Source Code Surpasses 40 Million Lines Linux Kernel Source Code Surpasses 40 Million Lines Mar 05, 2025 am 09:35 AM

Linux: The cornerstone of modern computing, from smartphones to supercomputers, can do everything. Over the years, the size and complexity of the Linux kernel has increased significantly. As of January 2025, the Linux kernel source code contains approximately 40 million lines of code! This is one of the greatest achievements in the history of open source, community-driven projects. This article will discuss the exponential growth of the number of lines in the Linux kernel source code, the reasons and how to check the current number of lines by yourself. Directory -Linux kernel history Count the number of lines of the Linux kernel source code only count C and header files Exponential trend of kernel growth Verify historical Linux kernel lines Summary Linux kernel history Since 1991 Linus Tor

How To Count Files And Directories In Linux: A Beginner's Guide How To Count Files And Directories In Linux: A Beginner's Guide Mar 19, 2025 am 10:48 AM

Efficiently Counting Files and Folders in Linux: A Comprehensive Guide Knowing how to quickly count files and directories in Linux is crucial for system administrators and anyone managing large datasets. This guide demonstrates using simple command-l

The Secret Weapon to Supercharge Your Linux System With Liquorix Kernel The Secret Weapon to Supercharge Your Linux System With Liquorix Kernel Mar 08, 2025 pm 12:12 PM

Liquorix kernel: a powerful tool to improve Linux system performance Linux is known for its flexibility, security and high performance, becoming the operating system of choice for developers, system administrators, and advanced users. However, the universal Linux kernel is not always meeting the needs of users seeking maximum performance and responsiveness. This is where the Liquorix kernel comes into play—a performance-optimized alternative that promises to enhance your Linux system. This article will explore what the Liquorix kernel is, why you might want to use it, and how to install and configure it to get the most out of your system. Liquorix kernel detailed explanation Liquorix kernel is a precompiled Linux kernel designed for

How To Add A User To Multiple Groups In Linux How To Add A User To Multiple Groups In Linux Mar 18, 2025 am 11:44 AM

Efficiently managing user accounts and group memberships is crucial for Linux/Unix system administration. This ensures proper resource and data access control. This tutorial details how to add a user to multiple groups in Linux and Unix systems. We

System76 Introduces Meerkat Mini PC: Big Power in a Tiny Package System76 Introduces Meerkat Mini PC: Big Power in a Tiny Package Mar 05, 2025 am 10:28 AM

The System76 Meerkat: A Mighty Mini PC Looking for a powerful yet space-saving computer? Meet the Meerkat mini PC from System76! This compact powerhouse is perfect for tidy desktops and demanding tasks. Table of Contents - Compact Design, Impressive

Building Your Own Ubuntu Personal Cloud: A Step-by-Step Guide to Creating a Secure Data Haven Building Your Own Ubuntu Personal Cloud: A Step-by-Step Guide to Creating a Secure Data Haven Mar 05, 2025 am 11:02 AM

In today's digital age, data is not just information, but also a part of our lives. From photos and documents to sensitive personal information, our data represents our memories, work and interests. Although cloud storage services are widely available, they are often accompanied by privacy concerns, subscription fees, and customization restrictions. That's what building a personal cloud on Ubuntu is about as a powerful alternative, which gives you complete control over your data and the flexibility to customize and scale as needed. This guide will guide you to set up a Ubuntu-based personal cloud, use Nextcloud as the primary application, and ensure your settings are secure and reliable. Why build a personal cloud on Ubuntu? Ubuntu is the most popular Linux

See all articles