Template:Lowercase Template:Short description {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other du, short for disk usage, is a shell command for reporting file system storage use Template:Endash 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.

HistoryEdit

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.<ref>Template:Man</ref> The command is also available for FreeDOS.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

A similar command is available on Windows via Sysinternals by Mark Russinovich.

UseEdit

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:

  • <syntaxhighlight lang="text" class="" style="" inline="1">-a</syntaxhighlight>, In addition to the default output, include information for each non-directory entry
  • <syntaxhighlight lang="text" class="" style="" inline="1">-c</syntaxhighlight>, Report the grand total of the storage usage for the specified scope
  • <syntaxhighlight lang="text" class="" style="" inline="1">-d #</syntaxhighlight>, 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
  • <syntaxhighlight lang="text" class="" style="" inline="1">-H</syntaxhighlight>, Calculate storage usage for link references specified on the command line
  • <syntaxhighlight lang="text" class="" style="" inline="1">-k</syntaxhighlight>, Show sizes as multiples of 1024 bytes, not 512-byte
  • <syntaxhighlight lang="text" class="" style="" inline="1">-L</syntaxhighlight>, Calculate storage usage for link references
  • <syntaxhighlight lang="text" class="" style="" inline="1">-s</syntaxhighlight>, Report only the sum of the usage of the starting scope directory; not for subdirectories
  • <syntaxhighlight lang="text" class="" style="" inline="1">-x</syntaxhighlight>, Only traverse files and directories on which the path argument is specified

Some implementations support other options. For example, BSD and GNU support a <syntaxhighlight lang="text" class="" style="" inline="1">-h</syntaxhighlight> option that selects numbers to be formatted using metric units and notation (e.g. 10 MB) instead of bytes.

ExamplesEdit

Report the storage use for each file and directory tree in kilobytes (<syntaxhighlight lang="text" class="" style="" inline="1">-k</syntaxhighlight>):

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

Report the storage use in a more human-readable format (<syntaxhighlight lang="text" class="" style="" inline="1">-h</syntaxhighlight>:

<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 (<syntaxhighlight lang="text" class="" style="" inline="1">-d 1</syntaxhighlight>) with a sum total at the end (<syntaxhighlight lang="text" class="" style="" inline="1">-c</syntaxhighlight>), formatted as human-readable (<syntaxhighlight lang="text" class="" style="" inline="1">-h</syntaxhighlight>):

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

For the GNU implementation, <syntaxhighlight lang="text" class="" style="" inline="1">--max-depth</syntaxhighlight> is used instead of <syntaxhighlight lang="text" class="" style="" inline="1">-d</syntaxhighlight>.

Report the storage use under the root directory (<syntaxhighlight lang="text" class="" style="" inline="1">-d 1</syntaxhighlight>, trailing Template:Char) with a sum total at the end (<syntaxhighlight lang="text" class="" style="" inline="1">-c</syntaxhighlight>), formatted as human-readable (<syntaxhighlight lang="text" class="" style="" inline="1">-h</syntaxhighlight>) without traversing into other file systems (<syntaxhighlight lang="text" class="" style="" inline="1">-x</syntaxhighlight>). 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 alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Disk space analyzers Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands