Linux Directory size shows no real-time problems

Source: Internet
Author: User
Tags parent directory

Before a friend in the group asked this question, why ls-l display the size of the directory is not the same as expected.

The problem is as follows

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/07/55/wKiom1nICBGxLXqUAAG6Xjck1ZE411.png-wh_500x0-wm_ 3-wmp_4-s_2812247567.png "title=" Directory size 1.png "alt=" Wkiom1nicbgxlxquaag6xjck1ze411.png-wh_50 "/>

Problem: Create 5,000 files in the data directory, this directory size changed, and then I deleted the 5,000 files, the size of this directory has not changed. Why?


To answer this question, we should first understand the storage principle of Linux files, everything in Linux is a file, from the root of the tree-like structure

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/A6/06/wKioL1nICQHz6mDpAAPnIPQaCD0071.png-wh_500x0-wm_ 3-wmp_4-s_3250223571.png "title=" Linux File system architecture. png "alt=" wkiol1nicqhz6mdpaapnipqacd0071.png-wh_50 "/>


Further down, the current directory's attribute information is actually in the block of its parent directory, such as size. By the knowable

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/07/55/wKiom1nICcCgndeLAATNSFAzOUY904.png-wh_500x0-wm_ 3-wmp_4-s_1141559994.png "title=" Directory size 2.png "alt=" Wkiom1nicccgndelaatnsfazouy904.png-wh_50 "/>


1. This is the attribute information of the file this information is stored in the block of the parent directory of this directory, called the directory entry. You have deleted all the files under this directory, but the directory entry information for this file has not been changed. So this has not changed, but this information has not changed, the space has been released.

2. Linux Ls-adh/A directory This command shows the size of the block of this directory, only the directory entries in this directory, the directory item size is not big, and the size of the file itself is not a matter of, even if you put 10G video files into a directory, The size of this directory may still be the initial value of 4K, as long as you do not put a lot of small video, but a few super-luxury HD video.

3. The reasonable explanation here is that when the size of the directory block becomes larger, Linux updates the directory block size in the directory entry information for this directory in its parent directory, but when this size becomes smaller, Linux does not automatically update this information.  But this information is not updated only, and other such as space and inode have all been collected by the system. In other words, the system does not have a problem, but this information is not smaller.

I think this is a bug in the Linux system. But it's also possible that system writers deliberately do this.

The reason may be that the Linux directory size is generally not too large this information can only retain the history of the largest value. As long as the space has been reclaimed by the system.

For verification, you can create a new 100,000 files and a few video large files, then look at the system inode remaining, and space remaining. Then delete these files, and you will find that the system reclaims all the space and inode, but the size of this directory is the same.


This article is from the "Love Life, Love Linux" blog, please be sure to keep this source http://baoyu.blog.51cto.com/9768109/1968283

Linux Directory size shows no real-time problems

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.