Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does Linux do when the file is deleted but the space is not released

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to deal with Linux files have been deleted but the space is not released, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The background of the problem

The server monitoring system of a business system sent an early warning notice that the disk space utilization rate had reached 90%, and then logged in to the server to search for relatively large log files, all of which were deleted (the hole was buried here). Some disk space was released, which was also negligent at that time, and did not confirm whether all the space of the file size found and deleted had been released. A few days later, the server was warned again, wondering how the log grew so fast. After investigation, it was found that it was caused by a large file space not released after the last operation to delete the file.

Problem reduction and solution

Find the data file that takes up more space

# check disk space usage $df-h# first query the files with large space in / tmp directory $du-sh / tmp/* | sort-nr | head-files with large space in query / home directory $du-sh / home/* | sort-nr | head-deleted files can be deleted after they are found. After deletion, use df-h to check whether they have been released.

Explain why when looking for files, you first look for the files in the / tmp/* directory.

Linux system deletion policy: Linux does not have the Recycle Bin function, so the files to be deleted by the service will be moved to the system / tmp directory first, and then the data in the / tmp directory will be cleared regularly.

There are many servers that do not partition / tmp separately when installing the system, so it is possible that the data in the / tmp directory takes up a large part of the space, so you can first clear the files in the / tmp directory to free up space.

The deletion of files does not free up space and occurs when a dubbo service log file is deleted in the / home directory space.

Reason why deleting files does not free up space

In general, there will be no space release after deleting a file, but it will occur when the file is locked by a process or when a process has been writing data to the file. If you understand the storage mechanism and storage structure of files under Linux, you will understand this problem.

The file stored in the Linux system is divided into two parts: the pointer part and the data part.

Pointer: stored in the meta-data of the file system, the pointer is removed from the meta-data after we execute the rm command to delete the data.

Data part: the data is stored directly on disk, and when the pointer is cleared from the meta-data, the space occupied by the data part can be overwritten and written to the new content.

The reason why the space is not released after deleting the dubbo log file is that the dubbo process is still writing data to this file, and when deleting the file, the pointer is not removed from the meta-data, so the log file still takes up space.

How to find this kind of file

You can get a list of files that have been deleted but are still occupied by the program through the lsof command:

Lsof | grep delete

How to release this kind of space

There are many ways to free up space for this type of problem: restart the occupied process, restart the operating system, and use the command. The first two methods are the most convenient for non-production environments, but for production environments, we should try to use commands, which are actually very simple:

Echo "" > / home/dubbo/log/xxx.log

In this way, the occupied disk space is released without affecting the process's continued execution.

The above is all the contents of the article "Linux how to deal with the file has been deleted but the space is not released". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report