du (Unix)

du
Original author(s)Dennis Ritchie
(AT&T Bell Laboratories)
Developer(s)Various open-source and commercial developers
Initial release3 November 1971; 53 years ago (1971-11-03)
Written inPlan 9, FreeDOS: C
Operating systemUnix, Unix-like, Plan 9, Inferno, FreeDOS
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3+
Plan 9: MIT License
FreeDOS: GPLv2

du is a shell command for reporting the file system storage allocated to files and directory trees. With no command-line arguments, it reports the space allocated to the working directory and to each directory tree that it contains, recursively. Space allocated to files is reported if files are specified for inclusion. For a symbolic link file, the size of the link file is reported; not what it links to.

Although du is short for disk usage, the command is not limited to disk storage. It was developed during the long period of time when disk-based storage was the ubiquitous mass storage technology.

du differs from df in that du reports size information of file system items whereas df reports statistics about the storage media as a whole. du can report more detailed information, but can take longer to complete when processing many files. Also, since a storage media may have allocated space that is not associated with an accessible file (i.e. file was deleted but space not freed), df might report more allocated space than du if it were used to calculate the space of all files of a media. Also, the minfree setting that allocates data blocks for the file system and the super user processes creates a discrepancy between total blocks and the sum of used and available blocks.

The du command first appeared in version 1 of AT&T UNIX. It is specified by the Single UNIX Specification (SUS). The implementation in GNU coreutils was written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering.[1] The command is also available for FreeDOS.[2] A similar command is available for Windows in Sysinternals by Mark Russinovich.

Use

[edit]

du accepts any number of parameters that each specify a file by path to specify the starting scope. If none specified, the working directory is used. SUS mandates the following optional options:

  • -a, In addition to the default output, include information for each non-directory entry
  • -c, Report the grand total of the storage usage for the specified scope
  • -d #, The maximum directory tree depth of the scope; deeper directories are ignored; for example, 0 sums the starting scope directory only and 1 sums the starting scope directory and its subdirectories
  • -H, Calculate storage usage for link references specified on the command line
  • -k, Show sizes as multiples of 1024 bytes, not 512-byte
  • -L, Calculate storage usage for link references
  • -s, Report only the sum of the usage of the starting scope directory; not for subdirectories
  • -x, Only traverse files and directories on which the path argument is specified

Some implementations support other options. For example, BSD and GNU support a -h option that selects numbers to be formatted using metric units and notation (e.g. 10 MB) instead of bytes.

Examples

[edit]

Report the storage use for each file and directory tree in kilobytes (-k):

$ du -sk * 152304  directoryOne 1856548 directoryTwo 

Report the storage use in a more human-readable format (-h:

$ du -sh * 149M directoryOne 1.8G directoryTwo 

Report the storage use of all subdirectories and files including hidden files within the working directory sorted by file size:

$ du -sk .[!.]* *| sort -n 

Report the storage use under in the working directory (-d 1) with a sum total at the end (-c), formatted as human-readable (-h):

$ du -d 1 -c -h 

For the GNU implementation, --max-depth is used instead of -d.

Report the storage use under the root directory (-d 1, trailing /) with a sum total at the end (-c), formatted as human-readable (-h) without traversing into other file systems (-x). Useful when /var, /tmp or other directories are on separate storage from the root directory:

$ du -d 1 -c -h -x / 

See also

[edit]

References

[edit]
  1. ^ du(1) – Linux User Commands Manual
  2. ^ "ibiblio.org FreeDOS 1.2 Updates Package -- du (Unix-like)". www.ibiblio.org.
[edit]