du (Unix)
![]() Example screenshot of du in a terminal | |
Original author(s) | Dennis Ritchie (AT&T Bell Laboratories) |
---|---|
Developer(s) | Various open-source and commercial developers |
Initial release | 3 November 1971 |
Written in | Plan 9, FreeDOS: C |
Operating system | Unix, Unix-like, Plan 9, Inferno, FreeDOS |
Platform | Cross-platform |
Type | Command |
License | coreutils: GPLv3+ Plan 9: MIT License FreeDOS: GPLv2 |
du
, short for disk usage, is a shell command for reporting file system storage use – space used for a file or a directory tree.
The Single UNIX Specification (SUS) specifies that by default, du
reports the space allocated to each file contained in the working directory. For a link file, the size of the link file itself is reported, not what it links to. The size of the content of directories is reported.
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
if files have been deleted but their blocks not yet freed. 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 minfree setting is usually set to about 5% of the total file system size. For more info see core utils faq.
History
[edit]The du
command first appeared in version 1 of AT&T UNIX.
The implementation of du
bundled 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 on Windows via 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]- Disk Usage Analyzer – Graphical disk usage analyzer for GNOME
- Filelight – Graphical disk usage analyzer software for KDE
- List of POSIX commands
- ncdu – Disk utility program
References
[edit]- ^ Linux User Commands Manual –
- ^ "ibiblio.org FreeDOS 1.2 Updates Package -- du (Unix-like)". www.ibiblio.org.
External links
[edit]- The Single UNIX Specification, Version 4 from The Open Group : estimate file space usage – Shell and Utilities Reference,
- Linux User Commands Manual –