Linux du command: Statistics directory or file share disk space

du statistical directory or file share disk space command.

It should be noted that the use of "ls -r" command can see the size of the file. But you will find that when using the "ls -r" command to view directory size, directory size is 4KB majority, because the subdirectory name and sub-directory under the file name is saved to the block parent directory (the default size is 4KB ) is, if the sub-subdirectories and files in the parent directory is not much you can put down a block, then the parent directory will only take up a block size.

We can think of it as a library book catalog and the actual books. If we use the "ls-l" command to view, you can only see these books take up a 1-page catalog of books, but the actual number of books in the end is not visible, even if it is filled with several rooms.

But we in the statistics directory, subdirectory name not want to see the child and parent directory under the file name in the end take up much space, but want to see the total disk footprint size subdirectories and subfolders under the parent directory, then you need to use real disk footprint size du command to statistics directory.

du command format is as follows:
[root @ localhost ~] # du [options] [directory or file name]

Options:
-a: show disk usage of each sub-file. The default disk footprint of only statistical subdirectories
-h: Displays the usage disk usage, such as KB, MB, or such as GB;
-s: Statistics Total disk usage, disk usage and not listed in the sub-subdirectories and files

[Example 1]
[root @ localhost ~] # du
# statistics of the current directory total disk footprint size, and it will count in the current directory disk footprint size for all subdirectories, not counting sub file
size # disk usage of. The default unit is KB
20 ./.gnupg
# statistics for each subdirectory of the size of the
24-./yum.bak
8 ./dtest
28 ./sh
188
# statistics the total size of the current directory

[Example 2]
[root @ localhost ~] # du -a
total size # statistics of the current directory, and it will count all child files and subdirectories disk usage of the size of the current directory. The default kilobytes (KB)

./.Bashjogout. 4
36 ./install.log
. 4 ./.bash_profile
. 4 ./.cshrc
... output omitted ...
188

[Example 3]
[root @ localhost ~] # du -SH
# only statistics the total size of the disk usage, and usage display unit
188K.

the difference between du and df command command
Sometimes we find that when using the command df and du command usage statistics to partition the data obtained is not the same. That is because the df command is considered from the perspective of the file system to determine the size of the file system space has been allocated by the file system space unallocated. In other words, when using partition df command statistics, not only to consider the space occupied by the file, but also statistics command or program space is occupied (the most common is the file has been deleted, but the program does not free up space).

The du command is file-oriented, will be counted only files or directories take up disk space. That is, df command partition statistics more accurate, is truly free space.

Published 160 original articles · won 97 Like · views 160 000 +

Guess you like

Origin blog.csdn.net/zyy1659949090/article/details/88176620