


The cleaning principle of /tmp/ folder in Linux system and the role of tmp file
Dec 21, 2023 pm 05:36 PMMost 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

Undress AI Tool
Undress images for free

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

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

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

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Gogo is a remarkable tool to bookmark directories inside your Linux shell. It helps you create shortcuts for long and complex paths in Linux. This way, you no longer need to type or memorize lengthy paths on Linux.For example, if there's a directory

PPA is an important tool for Ubuntu users to expand their software sources. 1. When searching for PPA, you should visit Launchpad.net, confirm the official PPA in the project official website or document, and read the description and user comments to ensure its security and maintenance status; 2. Add PPA to use the terminal command sudoadd-apt-repositoryppa:/, and then run sudoaptupdate to update the package list; 3. Manage PPAs to view the added list through the grep command, use the --remove parameter to remove or manually delete the .list file to avoid problems caused by incompatibility or stopping updates; 4. Use PPA to weigh the necessity and prioritize the situations that the official does not provide or require a new version of the software.

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

How to quickly generate test files of a specified size? It can be achieved using command line tools or graphical software. On Windows, you can use fsutilfilecreatenew file name size to generate a file with a specified byte; macOS/Linux can use ddif=/dev/zeroof=filebs=1Mcount=100 to generate real data files, or use truncate-s100M files to quickly create sparse files. If you are not familiar with the command line, you can choose FSUtilGUI, DummyFileGenerator and other tool software. Notes include: pay attention to file system limitations (such as FAT32 file size upper limit), avoid overwriting existing files, and some programs may

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

Node Version Manager (NVM) is a simple bash script that helps manage multiple Node.js versions on your Linux system. It enables you to install various Node.js versions, view available versions for installation, and check already installed versions.NV
