What is the difference between the size of the file shown with LS and du __shell script

Source: Internet
Author: User
Tags disk usage
Du = = Disk usage (disk usage, disk space occupied)
ls = = = Apparent sizes (file length, file length field defined in the Files data structure)
The amount of disk space a file occupies and the size of a file is a different situation. The footprint depends on the size of the file system block, Linux generally defaults to 4k (4096), so a file size of 1 bytes, the smallest to occupy 4k, if you create a filesystem when the block size is 16K, then even if a file only 1 bytes, Occupy space is also 16K.
In general, LS displays a smaller file size than the Du display, such as the file system block is 4K, a 13K file occupies a space of 13k/4k = 3.25 blocks, a block can only be occupied by one file, Therefore, the actual occupancy space is 4 blocks, is 16K.

Frequently found that RM deleted a file and the store was not freed

RM log file, but the log file has been opened by the process of service A, and the RM post space is not freed. RM is actually a link that deletes the file name to the location where the file is actually saved to the disk. At this point the file handle is also opened by service A, so the corresponding data is not recycled, in fact, can be understood as the reference count within the GC, RM just reduced the reference count, and did not really release the memory, when the reference count of 0, O The S kernel frees up space for other processes to use. So when a process stops (the reference count for the file handle changes to 0) or after the reboot, the storage space occupied is released. (lsof | grep deleted: Find all deleted files and corresponding processes that have not been released, and then kill the process or restart the process).


The log file is a sparse file, although its file length is large, however, it contains a large number of holes does not occupy the actual storage space.


The above is the use of DD and other commands to create sparse files, but also students with C code to achieve the same function. In fact, is the time to write the file, change the current file write pointer.


IF the environment variable BLOCKSIZE is set, and the-k option are not specified, the block counts would be displayed in UN Its in that size block. If BLOCKSIZE is not set, and the-k option isn't specified, the block counts would be displayed in 512-byte blocks.

Although the apparent size is usually smaller, it may was larger due to holes in (' sparse ') files, internal fragmentation, Indirect blocks, and the Like (Mans du)

Display values are in units of the the available SIZE from–block-size, and the Du_block_size, Block_size and BLOCKSIZE Environment variables. Otherwise, units default to 1024 bytes (or the If Posixly_correct is set. (Du--help)

You can modify the contents of the file to free up space without restarting the process, using echo ' Hello ' > Contentutil.log, and then DF to confirm that disk space has indeed been released.



Reference: http://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666540078&idx=2&sn= cacb3bcb3bd9a06cc8cfca16e02bfbd9&chksm= 80dce885b7ab619359cb73732a1505b440861af707a2abceed1de5d6496e96e82e1b76dce330&mpshare=1&scene=1& Srcid=12061rcrjhaoxf9ctqtcuweb#rd

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.