Linux view directory size and hard disk size

  
                  Linux view directory size and hard disk size command: # du -ks ---in all# du -k ---every lastdu and df commands are used to get the file system size information: df is used to report the total file system The number of blocks and the number of remaining blocks, du -s /is used to report the number of blocks used by the file system. However, we can find that the value of the number of blocks used by the file system calculated from the df command is inconsistent with the value obtained by 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. The difference in value is due to the difference in the implementation of the du and df commands: The du -s command accumulates the total number of blocks used by the file system by accumulating the number of blocks used by all directories, symbolic links, and files in the specified file system; The df command returns the total number of blocks and the number of remaining blocks by looking at the file system disk block allocation map. The file system allocates some of the disk blocks to record some of its own data, such as i-nodes, disk maps, indirect blocks, superblocks, and so on. This data is invisible to most user-level programs and is often referred to as Meta Data. The du command is a user-level program that does not consider Meta Data, while the df command looks at the disk allocation map of the file system and considers Meta Data. The df command gets the real file system data, while the du command only looks at some parts of the file system. For example, a frag=4096 and nbpi=4096 empty 4MB log file system Meta Data is allocated as follows: 1 4k block for the LVM2 4k super blocks2 4k blocks for disk maps2 4k blocks for inode maps2 4k blocks for .indirect32 4k blocks for inodes-------------------------41 4k blocks for meta data on an empty 4MB file system for AIX 4.X versions: The result of executing du /foo is as follows: ----8 -------/foo/lost+found----16 ------/foo wants to output the result of the du command with the df command The output results match, we have to add Meta Data. First, convert 41 4k blocks to values ​​in 512-byte units: 41 * 8 = 328328(meta data) + 16(from du) = 344 so there are 344 blocks allocated in 512-byte units. This empty file system. Using the df /foo command we can get the following result: Filesystem --512-blocks --Free --%Used --Iused---%Iused --Mounted on/dev/lv01 ------8192 - ----7848 -----5% -----16 -----2% ----/foo from which we can get the number of blocks used by the file system: 8192 (total blocks) - 7848 (free blocks) = 344. This value is consistent with the value obtained above. The above conversion method is easy to implement for an empty file system, but for a non-empty file system, it is difficult to implement because the size of the indirect block of the file in Meta Data is variable. So we don't need to look at the matching relationship between du and the value returned by df, but only need to know that the value returned by the du -s command reflects the number of disk blocks allocated to files and directories, and 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 showing the difference between du and df commands is as follows: If the user deletes a file in a directory opened by a running application, the value returned by the du command shows the directory after the file is subtracted. the size of. However, the df command does not display the size after subtracting the file. Until the running application closes the open file, the value returned by df shows the usage of the file system after subtracting the file. List the space occupied by a directory 1. du or du -s or du -k du -S
Copyright © Windows knowledge All Rights Reserved