# Du (Unix)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Du_(Unix)
> Markdown URL: https://mediated.wiki/source/Du_(Unix).md
> Source: https://en.wikipedia.org/wiki/Du_(Unix)
> Source revision: 1336328130
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{lowercase}}
{{short description |Shell command for reporting file system storage use}}
{{Infobox software
| name                   = du
| logo                   = 
| screenshot             = Du-example-command.gif
| screenshot size        = 
| caption                = Example screenshot of <code>du</code> in a terminal
| author                 = [Dennis Ritchie](/source/Dennis_Ritchie)<br />([AT&T Bell Laboratories](/source/AT%26T_Bell_Laboratories))
| developer              = Various [open-source](/source/open-source_software) and [commercial](/source/commercial_software) developers
| released               = {{Start date and age|1971|11|03|df=y}}
| latest release version = 
| latest release date    = 
| programming language   = Plan 9, FreeDOS: [C](/source/C_(programming_language))
| operating system       = [Unix](/source/Unix), [Unix-like](/source/Unix-like), [Plan 9](/source/Plan_9_from_Bell_Labs), [Inferno](/source/Inferno_(operating_system)), [FreeDOS](/source/FreeDOS)
| platform               = [Cross-platform](/source/Cross-platform)
| genre                  = [Command](/source/Command_(computing))
| license                = [coreutils](/source/coreutils): [GPLv3+](/source/GPLv3%2B)<br />Plan 9: [MIT License](/source/MIT_License)<br />FreeDOS: [GPLv2](/source/GPLv2)
| website                = 
}}
'''<code>du</code>''' is a [shell](/source/shell_(computing)) [command](/source/command_(computing)) for reporting the [file system](/source/file_system) storage allocated to [files](/source/computer_file) and [directory tree](/source/directory_tree)s. With no [command-line argument](/source/command-line_argument)s, it reports the space allocated to the [working directory](/source/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](/source/symbolic_link) file, the size of the link file is reported, not what it links to.

Although ''du'' is short for '''''d'''isk '''u'''sage'',<ref>{{Cite web|url=https://www.nokia.com/bell-labs/about/dennis-m-ritchie/man12.pdf#page=6|title=Unix Programmer's Manual November 3, 1971|access-date=September 22, 2025|archive-date=December 28, 2025|archive-url=https://web.archive.org/web/20251228181711/https://www.nokia.com/bell-labs/about/dennis-m-ritchie/man12.pdf#page=6|url-status=live}}</ref> the command is not limited to [disk storage](/source/disk_storage). It was developed during the long period of time when disk-based storage was the ubiquitous [mass storage](/source/mass_storage) technology.

{{code |du}} differs from <code>[df](/source/df_(Unix))</code> in that {{code |du}} reports size information of file system items whereas {{code |df}} reports [statistics](/source/statistics) about the storage media as a whole. {{code |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), {{code |df}} might report more allocated space than {{code |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 <code>du</code> command first appeared in version 1 of [AT&T UNIX](/source/History_of_Unix). It is specified by the [Single UNIX Specification](/source/Single_UNIX_Specification) (SUS). The implementation in [GNU](/source/GNU) [coreutils](/source/coreutils) was written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering.<ref>{{man|1|du|die.net}}</ref> The command is also available for [FreeDOS](/source/FreeDOS).<ref>{{Cite web|url=https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/du.html|title=ibiblio.org FreeDOS 1.2 Updates Package -- du (Unix-like)|website=www.ibiblio.org|access-date=2022-07-02|archive-date=2022-07-02|archive-url=https://web.archive.org/web/20220702062503/https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/du.html|url-status=live}}</ref> A similar command is available for [Windows](/source/Windows) in [Sysinternals](/source/Sysinternals) by [Mark Russinovich](/source/Mark_Russinovich).

==Use==
<code>du</code> accepts any number of parameters that each specify a file by [path](/source/path_(computing)) to specify the starting scope. If none specified, the working directory is used. SUS mandates the following optional options:

* {{code|-a}}: In addition to the default output, include information for each non-directory entry
* {{code|-c}}: Report the grand total of the storage usage for the specified scope
* {{code|-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
* {{code|-H}}: Calculate storage usage for link references specified on the command line
* {{code|-k}}: Show sizes as multiples of 1024 [byte](/source/byte)s, not 512-byte
* {{code|-L}}: Calculate storage usage for link references
* {{code|-s}}: Report only the sum of the usage of the starting scope directory, and not that of subdirectories
* {{code|-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 {{code|-h}} option that selects numbers to be formatted using metric units and [notation](/source/SI_prefix) (e.g. 10 [MB](/source/megabyte)) instead of bytes.

==Examples==
Report the storage use for each file and directory tree in [kilobyte](/source/kilobyte)s ({{code|-k}}):

<syntaxhighlight lang="console">
$ du -sk *
152304  directoryOne
1856548 directoryTwo
</syntaxhighlight>

Report the storage use in a more [human-readable](/source/human-readable) format ({{code|-h}}:

<syntaxhighlight lang="console">
$ du -sh *
149M directoryOne
1.8G directoryTwo
</syntaxhighlight>

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

<syntaxhighlight lang="console">
$ du -sk .[!.]* *| sort -n
</syntaxhighlight>

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

<syntaxhighlight lang="console">
$ du -d 1 -c -h
</syntaxhighlight>

For the GNU implementation, {{code|--max-depth}} is used instead of {{code|-d}}.

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

<syntaxhighlight lang="console">
$ du -d 1 -c -h -x /
</syntaxhighlight>

==See also==
* {{Annotated link|Disk Usage Analyzer}}
* {{Annotated link|Filelight}}
* {{Annotated link|List of POSIX commands}}
* {{Annotated link|ncdu}}

==References==
{{Reflist}}

==External links==
{{Wikibooks|Guide to Unix|Commands}}
* {{man|cu|du|SUS|estimate file space usage}}
* {{man|1|du|die.net}}

{{Disk space analyzers}}
{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}

Category:Standard Unix programs
Category:Unix SUS2008 utilities
Category:Plan 9 commands
Category:Inferno (operating system) commands
Category:Disk usage analysis software
Category:Unix file system-related software

---
Adapted from the Wikipedia article [Du (Unix)](https://en.wikipedia.org/wiki/Du_(Unix)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Du_(Unix)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
