TrumanWong

du

Shows disk space usage for each file and directory

Supplementary instructions

The du command also checks the space used, but unlike the df command, the Linux du command checks the space used by files and directory disks, which is somewhat different from the df command.

grammar

du [options][file]

Options

-a, --all Display the size of individual files in the directory.
-B, --block-size=size Use blocks of the specified number of bytes
-b, --bytes When displaying the size of a directory or file, the unit is byte.
-c, --total In addition to displaying the size of individual directories or files, it also displays the total size of all directories or files.
-D, --dereference-args Display the source file size of the specified symbolic link.
-d, --max-depth=N limit folder depth
-H, --si are the same as -h parameters, but K, M, and G are converted in units of 1000.
-h, --human-readable Use K, M, G as units to improve the readability of information.
-k, --kilobytes output in KB (1024bytes).
-l, --count-links Repeat counting of hardware link files.
-m, --megabytes Output in MB.
-L<symbolic link>, --dereference<symbolic link> Display the source file size of the symbolic link specified in the option.
-P, --no-dereference do not follow any symbolic links (default)
-0, --null Treat each empty line as 0 bytes instead of a newline character
-S, --separate-dirs When displaying the size of individual directories, the size of its subdirectories is not included.
-s, --summarize Display only the total, listing only the last summed value.
-x, --one-file-xystem The file system at the beginning of processing shall prevail. If other different file system directories are encountered, they will be ignored.
-X<file>, --exclude-from=<file> Specifies the directory or file in <file>.
--apparent-size displays surface usage, not disk usage; although surface usage is usually smaller, it can sometimes become larger due to "holes" between sparse files, internal fragmentation, non-directly referenced blocks, etc.
--files0-from=F Calculate the disk space occupied by the NUL-terminated file name in file F. If the value of F is "-", read the file name from the standard input.
--exclude=<directory or file> Ignore the specified directory or file.
--max-depth=N Display directory total (used with --all to calculate files). When N is the specified value, the calculated depth is N. When it is equal to 0, it is equivalent to --summarize
--si Like -h, but uses 1000 as the base instead of 1024 when calculating
--time displays the last modification time of all files in a directory or subdirectories of the directory
--time=WORD Display WORD time, not modification time: atime, access, use, ctime or status
--time-style=Style Display time according to the specified style (style interpretation rules are the same as the "date" command): full-iso, long-iso, iso, +FORMAT
--help Display this help message and exit
--version Display version information and exit

Example

Sort files from largest to smallest

ubuntu@VM-0-14-ubuntu:~/git-work/linux-command$ du -sh * |sort -rh
2.9M command
1.9M assets
148K template
72K package-lock.json
52K dist
28K build
16K README.md
4.0K renovate.json
4.0K package.json
4.0K LICENSE

Only the size of subdirectories under the current directory is displayed.

ubuntu@VM-0-14-ubuntu:~/git-work/linux-command$ du -sh ./*/
1.9M ./assets/
28K ./build/
2.9M ./command/
52K ./dist/
148K ./template/

Check the space occupied by files in a specified directory:

ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du ./*
144 ./alfred.png
452 ./chrome-extensions.gif
4./dash-icon.png
1312 ./Linux.gif
16./qr.png

Show only the size of the sum:

ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du -s .
1932.

Show the size of the sum and make it easy to read:

ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du -sh .
1.9M.