Focus on cloud service provider activities
Notes on website operation and maintenance

Use the tmpwatch command to clean the tmp cache content to improve disk storage utilization

Lao Zuo mentioned in a previous article that he was helping netizens solve the problem of full server disks( Record and solve the problem of insufficient AliCloud server disks without purchasing attached data disks )Among them, Lao Zuo found that the main problem was the caching of the tmp directory. He had 12GB of space occupied here, while the 6GB log file was not split, and the logs of so many days were directly in it.

If it is troublesome to delete the directory tmp cache file, you can directly use tmpwatch to solve this problem.

1. Install tmpwatch

yum install tmpwatch

We can install it first. Sometimes the server image is not automatically installed.

2. Execute command

tmpwatch -afv 3 /tmp/

This command is used to clean the cached tmp files within three hours. Let's see what tmpwatch means

tmpwatch – removes files which haven’t been accessed for a period of time

It can be seen from the explanation that it deals with the occupation of unused files.

3. Using Commands

Here I will sort out other uses of parameters and learn about them. If they need to be used later.

-u. – atime deletes files based on access time, which is the default.

-m. – mtime deletes files based on the modification time.

-c. – ctime deletes files based on the creation time. For directories, it deletes files based on mtime.

-M. – dirmtime Deleting a directory is based on the modification time of the directory rather than the access time.

-a. – all Deletes all file types, not just ordinary files, symbolic links, and directories.

-d. – nodirs does not attempt to delete a directory, even if it is empty.

-d. – nosymlinks does not attempt to delete symbolic links.

-f. – force Force deletion.

-q. – quiet only reports error information.

-s. – fuser If the file is already open, try to use the "Fusing" command before deleting it. Not enabled by default.

-t. – Test is only for testing, and does not really delete files or directories.

-U. – exclude user=user does not delete whose files belong to.

-v. – verbose Print details.

-x. – exclude=path Excludes the path. If the path is a directory, all the files it contains are excluded. If the path does not exist, it must be an absolute path without symbolic links.

-10. – exclude pattern=pattern Excludes paths under a rule.

In conclusion, attention should be paid here. If we can't, we can use it in the test environment first, or make a backup.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Use the tmpwatch command to clean the tmp cache content to improve disk storage utilization