Linux View directory size and hard disk size

Source: Internet
Author: User
Tags empty file system

Linux View directory size and hard drive size commands:

# Du-ks---in all

# du-k---every last

Both Du and DF commands are used to obtain information about the file system size: DF is used to report the total number of blocks and the number of blocks remaining in the filesystem, du-s/used to report the number of blocks used by the file system. However, we can find that the file system calculated from the DF command uses the value of the block number to be inconsistent with the value derived from the du command. The following example:

# DU-S/tmp returns the following values:

---12920/tmp

And Df/tmp returns the following values:

FileSystem--512-blocks--Free--%used--iused--%iused--mounted on

/DEV/HD3--------57344--42208---26%----391------4%--/tmp

From the above values we can calculate-=: 57344-42208 = 15136. And 15136 is greater than 12920. This value difference exists because of the difference between Du and DF command implementations: The DU-S command accumulates the total number of blocks used by the filesystem by adding the number of blocks used for all directories, symbolic links, and files in the specified file system, while the DF command obtains the total block count and the remaining blocks by viewing the file system disk block allocation graph.

The file system allocates some of these disk blocks to record some of its own data, such as I nodes, disk maps, indirect blocks, super blocks, and so on. This data is not visible to most user-level programs, often called Meta data.

The du command is a user-level program that does not consider meta data, while the DF command looks at the file system's disk allocation graph and considers meta data. The DF command obtains real file system data, while the DU command only looks at part of the file system. For example, the allocation of meta data in a frag=4096 and nbpi=4096 log file system with an empty size of 4MB is as follows:

1 4k block for the LVM

2 4k Super Blocks

2 4k blocks for disk maps

2 4k blocks for inode maps

2 4k blocks for. Indirect

4k blocks for Inodes

-------------------------

4k blocks for meta-data on a empty 4MB file system

For AIX 4.X versions:

The results of the execution Du/foo return are as follows:

----8-------/foo/lost+found

----------/foo

For the results of the du command output to match the output of the DF command, we must add Meta Data. First, the 41 4k blocks are converted to values in 512-byte units:

41 * 8 = 328

328 (meta data) + (from du) = 344

So there are 344 blocks of 512 bytes allocated to this empty file system.

and using the Df/foo command we can get the following results:

FileSystem--512-blocks--free--%used--iused---%iused--mounted on

/DEV/LV01------8192-----7848-----5%----------2%----/foo

From this we can get the number of blocks used by the filesystem: 8192 (Total blocks)-7848 (free blocks) = 344. The value is consistent with the value derived above.

The above conversion method is easy to implement for empty file systems, but for Non-empty file systems, the size of the file indirect blocks in Meta data is difficult to implement. So we don't need to look at the match between Du and the values returned by DF, only to understand that the value returned by the Du-s command reflects the number of disk blocks allocated to the file and directory, while the DF command reflects the actual allocation of the file system. The actual situation reflected by the DF command includes user data (files and directories) and meta data.

Another example that shows the difference between Du and DF commands is as follows:

If a user deletes a file in a directory that is open by a running application, the value returned by the du command displays the size of the directory after the file has been subtracted. However, the DF command does not show the size of the file after subtracting it. Until the running application closes the open file, DF Returns a value that shows the file system usage after subtracting the file.

Lists the space occupied by a directory

1. du or Du-s or du-k

Du-s | Sort-n can quickly find that the directory is the largest.

2. DF can be used to see the installed file system space size and the amount of space remaining.

3. Quota-v View the user's disk space information, if you use quota limit the size of the user space.

Related Article

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.