The du command is used to estimate the disk usage of the file system. It is often used to see how many disks are occupied by files or directories. The du command also looks at the space used, but unlike df, Linux du looks at the space used on files and directory disks. There are some differences with df.

Command syntax

Du [option][file]

Command options

  • -a, –all shows the size of individual files in the directory.
  • -b, –block-size= Size of a block that uses the specified number of bytes
  • -b, –bytes Displays the size of a directory or file in bytes.
  • -c, –total shows the total of all directories or files in addition to the size of individual directories or files.
  • -d, –dereference-args Displays the size of the source file for the specified symbolic link.
  • -h, –si and -h have the same parameters, but K, M, and G are converted in units of 1000.
  • –h, –human — readable in units of K, M, G to improve the readability of the information.
  • -k, — Kilobytes output in KB(1024bytes).
  • -l, — Count-Links files that repeatedly count hardware links.
  • -m, — file size in megabytes
  • -l < symbolic link >, –dereference< symbolic link > The size of the source file for the symbolic link specified in the display option.
  • -p, –no-dereference does not follow any symbolic links (default)
  • -0, –null treats each blank line as a 0 byte instead of a newline character
  • -s, –separate-dirs Shows the size of an individual directory, not the size of its subdirectories.
  • -s, — Summarize only shows the sum and lists only the last sum.
  • -x, –one-file-xystem is based on the file system where it was first processed, skipping it if a different file system directory is encountered.
  • -x < file >, –exclude-from=< file > specify directory or file in < file >.
  • –apparent size displays surface size, not disk size; Although the surface amount is usually smaller, it can sometimes become larger due to “holes” between sparse files, internal fragments, blocks that are not directly referenced, and so on.
  • –files0-from=F Calculates the amount of disk space used for filenames ending in NUL in the file F. If F is “-“, then read the filename from standard input
  • –exclude=< directory or file >
  • — math-depth =N Summarize — Summarize — Summarize — Summarize — Summarize — Summarize — Summarize — Summarize — Summarize
  • — Si is similar to -H, but calculates with a base of 1000 instead of 1024
  • –time Displays the last modified time of all files in the directory or subdirectories of the directory
  • –time=WORD Display WORD time, not modified time: atime, access, use, ctime or status
  • –time-style= The style displays the time in the specified style (the style interpretation rules are the same as the “date” command) : full-iso, long-iso, iso, +FORMAT
  • –help displays this help information and exits
  • –version displays version information and exits

Displays the size of the directory

du
0       ./lib
12      ./bin/rumenz
12      ./bin
0       ./sbin/doc
0       ./sbin/info
4       ./sbin
0       ./doc/js
0       ./doc/css
0       ./doc/html/rumenz
0       ./doc/html/rumenzz
4       ./doc/html
4       ./doc
0       ./rumenz/lib/test
0       ./rumenz/lib/info
0       ./rumenz/lib
0       ./rumenz
52      ./one
104     .

Displays only the directory size of subdirectories under the current directory and the total size of the current directory. The bottommost 104 is the total size of the current directory

Displays the disk space occupied by the specified file

> du rumenz.txt

View the space occupied by the specified directory

> du src
0       src/lib
12      src/bin/rumenz
12      src/bin
0       src/sbin/doc
0       src/sbin/info
4       src/sbin
0       src/doc/js
0       src/doc/css
0       src/doc/html/rumenz
0       src/doc/html/rumenzz
4       src/doc/html
4       src/doc
0       src/rumenz/lib/test
0       src/rumenz/lib/info
0       src/rumenz/lib
0       src/rumenz
52      src/one
104     src/

The last line is the entire directory
srcThe amount of disk space occupied

To improve the readability of information, look at the space taken up by a given directory

> du-h SRC 0 SRC /lib 12K SRC /bin/rumenz 12K SRC /bin 0 SRC /sbin/doc 0 SRC /sbin/info 4.0K SRC /sbin 0 SRC /doc/js 0 SRC /doc/ CSS 0 SRC /doc/ HTML /rumenz 0 SRC /doc/ HTML /rumenzz 4.0k SRC /doc/ HTML 4.0k SRC /doc/ HTML 4.0k SRC /rumenz/lib/test 0 src/rumenz/lib/info 0 src/rumenz/lib 0 src/rumenz 52K src/one 104K src/

The last line is the entire directory
srcOccupy disk space, plus units, readability becomes stronger

Displays the space taken up by multiple files

> du  a.log b.log
0       a.log
0       b.log

Shows only the total size of the directory

> du -s /root
826036  /root

Total Statistical Consumption (
-sOn behalf of
summarize)

Shows only the total size of the directory to improve readability

> du -sh /root/
807M    /root/

The file and directory sizes are shown

> du-ah SRC / 0 SRC /lib 0 SRC /bin/rumenz/5.txt 0 SRC /bin/rumenz/3.txt 8.0k SRC /bin/rumenz/5.txt~ 4.0k SRC /bin/rumenz/1.txt 12K SRC /bin/rumenz 12K SRC /bin 0 SRC /sbin/doc 0 SRC /sbin/info 4.0k SRC /sbin/rumenz.txt 4.0k SRC /sbin 0 SRC /doc/js 0 SRC /doc/ CSS 4.0k SRC /doc/ HTML /1.sh 0 SRC /doc/ HTML /1.txt 0 SRC /doc/ HTML /2.txt 0 src/doc/html/rumenz/1.txt 0 src/doc/html/rumenz/2.txt 0 src/doc/html/rumenz 0 src/doc/html/rumenzz/1.txt~ 0 SRC/doc/HTML/rumenzz / 1. TXT 0 SRC/doc/HTML/rumenzz 0 SRC/doc/HTML / 1 _link. TXT 4.0 K 0 SRC/doc/SRC/doc/HTML rumenz. TXT 4.0 K SRC /doc 0 SRC /rumenz/lib/test 0 SRC /rumenz/lib/info 0 SRC /rumenz/lib 0 SRC /rumenz/lib 0 SRC /rumenz 4.0k SRC /InfiniteLoop$1.class 4.0k SRC/infiniteloop.class 12K SRC /nohup.out 4.0k SRC/infiniteloop.java 4.0k SRC /rumenz.txt 4.0k SRC /rumenz.txt 0 SRC/abc1.png 0 SRC/ab2.png 0 SRC/abc123.png 0 SRC/a123.png 0 SRC /b.log 4.0k SRC /one/rumenz.tar.gz 0 SRC /one/1.txt 0 SRC /one/2.txt 48K SRC /one/etc.tar.gz 52K SRC /one 4.0k SRC /a.log 108K SRC /

Displays the amount of disk space each of several files or directories takes up, and counts them together

> du -c a.log b.log 
4       a.log
0       b.log
4       total

With the -c option, du not only shows how much disk space each of the two directories occupies, it also adds them up on the last line.

Sort by space size

> du -ah src | sort -nr 108K ./src 108K . 52K ./src/one 48K ./src/one/etc.tar.gz 12K ./src/nohup.out 12K ./ SRC /bin/rumenz 12K./ SRC /bin 8.0k./ SRC /bin/rumenz/5.txt~ 4.0k./ SRC /bin/ rumenz.txt 4.0k ./ SRC /rumenz.txt 4.0K./ SRC /rumenz.txt 4.0K./ SRC /one/rumenz.tar.gz 4.0K./ SRC /InfiniteLoop.java 4.0k ./ SRC /InfiniteLoop. Class 4.0k./ SRC /InfiniteLoop$1. Class 4.0k./ SRC /doc/ HTML /1.sh 4.0k./ SRC /doc/ HTML / 4.0k 4.0k./ SRC /bin/rumenz/1.txt 4.0k./ SRC /a.log 0./ SRC /sbin/info 0./ SRC /sbin/doc 0 ./src/rumenz/lib/info 0 ./src/rumenz/lib 0 ./src/rumenz 0 ./src/one/2.txt 0 ./src/one/1.txt 0 ./src/lib 0 ./src/doc/rumenz.txt 0 ./src/doc/js 0 ./src/doc/html/rumenzz/1.txt~ 0 ./src/doc/html/rumenzz/1.txt 0 ./src/doc/html/rumenzz 0 ./src/doc/html/rumenz/2.txt 0 ./src/doc/html/rumenz/1.txt 0 ./src/doc/html/rumenz 0 ./src/doc/html/2.txt 0 ./src/doc/html/1.txt 0 ./src/doc/html/1_link.txt 0 ./src/doc/css 0 ./src/b.log 0 ./src/bin/rumenz/5.txt 0 ./src/bin/rumenz/3.txt 0 ./src/ABC1.png 0 ./src/ABC123.png 0 ./src/AB2.png 0 ./src/A123.png

Outputs the space used by each subdirectory under the current directory

> du-h --max-depth SRC 0 SRC /lib 12K SRC /bin 4.0k SRC /sbin 4.0k SRC /doc 0 SRC /rumenz 52K SRC /one 108K SRC

The original link: https://rumenz.com/rumenbiji/… WeChat official account: entry station