Linux deletes files, but space does not release

Source: Internet
Author: User

1, Problem Description:

Rm/tmp/access_log after deleting large files through RM, the view disk results show that the disk occupation is still 100% and the space is not released.



2, solve the idea

In general, the deletion of files after the space does not release, but there are exceptions, such as the file is locked by the process, or a process has been writing data to this file and so on, to understand this problem, you need to know the Linux file storage mechanism and storage structure.

A file in the file system is divided into two parts: the data part and the pointer part, the pointer is located in the file system Meta-data, the data is deleted, the pointer is removed from the Meta-data, and the data portion is stored on disk, the data corresponding to the pointer from the Meta-data purged , the space occupied by the file data can be overwritten and written to the new content, the reason for the deletion of the Access_log file, the space is not released, because the httpd process is still writing to this file, resulting in the deletion of access_log files, However, the pointer part of the file corresponding to the process lock, not purged from the meta-data, and because the pointer is not deleted, then the system kernel thinks the file has not been deleted, so it is not surprising that the DF command to query the space is not released.


3. Troubleshooting

Since there is a solution to the problem, then see if there is a process has been writing data to the Acess.log file, here need to use the Linux lsof command, through this command can get a deleted but still be occupied by the application of the file list, command execution as shown:

Lsof |grep Delete



As you can see from the output,/tmp/ Acess.log file is locked by the process httpd, and the httpd process has been written to this file log data, from the seventh column, the log file size is only 70G, and the total system root partition size is only 100G, it is known that this file is the culprit that causes the system root partition space exhaustion, in the last column of the "deleted" state, indicating that the log file has been deleted, but because the process is still writing data to this file, the space is not released.


4, solve the problem


Here the problem is basically clear, there are many ways to solve this kind of problem.

The simplest way is to shut down or restart the httpd process, of course, can also restart the operating system, but this is not the best way to treat the process of the file log operation, to free the disk space occupied by the file, the best way is to empty the file online, can be completed by the following command:

echo "" >/tmp/acess.log

This way, disk space can not only be released immediately, but also to ensure that the process continues to write to the file log, this method is often used to online clean Apache, Tomcat, Nginx and other Web services generated by the log files.


This article is from the "Silent Dialogue" blog, please be sure to keep this source http://chbinmile.blog.51cto.com/6085145/1872633

Linux deletes files, but space does not release

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.