Du (Unix) Explained

du
Author:Dennis Ritchie
(AT&T Bell Laboratories)
Developer:Various open-source and commercial developers
Programming Language:Plan 9, FreeDOS: C
Operating System:Unix, Unix-like, Plan 9, Inferno, FreeDOS
Platform:Cross-platform
Genre:Command
License:coreutils

GPLv3+
Plan 9: MIT License
FreeDOS: GPLv2

du (abbreviated from disk usage) is a standard Unix program used to estimate file space usage—space used under a particular directory or files on a file system. A Windows commandline version of this program is part of Sysinternals suite by Mark Russinovich.

History

The du utility first appeared in version 1 of AT&T UNIX. The version of du bundled in GNU coreutils was written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering. The command is also available for FreeDOS.[1]

Specification

By default, the Single UNIX Specification (SUS) specifies that du is to display the file space allocated to each file and directory contained in the current directory. Links will be displayed as the size of the link file, not what is being linked to; the size of the content of directories is displayed, as expected.

As du reports allocation space and not absolute file space, the amount of space on a file system shown by du may vary from that shown by [[df (Unix)|df]] if files have been deleted but their blocks not yet freed. Also the minfree setting that allocates datablocks for the filesystem and the super user processes creates a discrepancy between total blocks and the sum of used and available blocks. The minfree setting is usually set to about 5% of the total filesystem size. For more info see core utils faq.

Usage

du takes a single argument, specifying a pathname for to work; if it is not specified, the current directory is used. The SUS mandates for the following options:

Other Unix and Unix-like operating systems may add extra options. For example, BSD and GNU du specify a option, displaying disk usage in a format easier to read by the user, adding units with the appropriate SI prefix (e.g. 10 MB).

Examples

Sum of directories (-s) in kilobytes (-k):$ du -sk *152304 directoryOne1856548 directoryTwoSum of directories (-s) in human-readable format (-h : Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte):$ du -sh *149M directoryOne1.8G directoryTwodisk usage of all subdirectories and files including hidden files within the current directory (sorted by filesize) :$ du -sk .[!.]* *| sort -ndisk usage of all subdirectories and files including hidden files within the current directory (sorted by reverse filesize) :$ du -sk .[!.]* *| sort -nr

The weight (size) of each subdirectory under the current directory (-d 1) with a sum total at the end (-c) all displayed in human-readable format (-h):$ du -d 1 -c -hor with du from GNU:$ du --max-depth=1 -c -h

The weight (size) of subdirectories under the root directory (-d 1, trailing /) with a sum total at the end (-c), all displayed in human-readable format (-h) without traversing into other filesystems (-x). Useful when /var /tmp or other directories are on separate storage from the root directory:$ du -d 1 -c -h -x /or with du from GNU:$ du --max-depth=1 -c -h -x /

See also

Notes and References

  1. Web site: ibiblio.org FreeDOS 1.2 Updates Package -- du (Unix-like). www.ibiblio.org.