Jump to content

Du (Unix): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
there has been a version for windows for quite some time
No edit summary
Tags: Mobile edit Mobile web edit
 
(5 intermediate revisions by 3 users not shown)
Line 4: Line 4:
| name = du
| name = du
| logo =
| logo =
| screenshot = Du screenshot.png
| screenshot = Du-example-command.gif
| screenshot size =
| screenshot size =
| caption = Example screenshot of <code>du</code> in a terminal
| caption = Example screenshot of <code>du</code> in a terminal
| author = [[Dennis Ritchie]]<br />([[AT&T Bell Laboratories]])
| author = [[Dennis Ritchie]]<br />([[AT&T Bell Laboratories]])
| developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers
| developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers
| released = {{Start date and age|1971|11|03}}
| released = {{Start date and age|1971|11|03|df=y}}
| latest release version =
| latest release version =
| latest release date =
| latest release date =
| programming language = Plan 9, FreeDOS: [[C (programming language)|C]]
| operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[FreeDOS]]
| operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[FreeDOS]]
| platform = [[Cross-platform]]
| platform = [[Cross-platform]]
| genre = [[Command (computing)|Command]]
| genre = [[Command (computing)|Command]]
| license = [[coreutils]]: [[GPLv3+]]
| license = [[coreutils]]: [[GPLv3+]]<br />Plan 9: [[MIT License]]<br />FreeDOS: [[GPLv2]]
| website =
| website =
}}
}}
Line 21: Line 22:


==History==
==History==
The <code>du</code> utility first appeared in version 1 of [[History_of_Unix#1970s|AT&T UNIX]]. The version of <code>du</code> bundled in [[GNU]] [[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]].<ref>{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/group-unixlike.html|title=ibiblio.org FreeDOS Group -- Unix-like|website=www.ibiblio.org}}</ref>
The <code>du</code> utility first appeared in version 1 of [[History_of_Unix#1970s|AT&T UNIX]]. The version of <code>du</code> bundled in [[GNU]] [[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]].<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}}</ref>


==Specification==
==Specification==
Line 30: Line 31:
==Usage==
==Usage==
<code>du</code> takes a single argument, specifying a pathname for {{mono|du}} to work; if it is not specified, the current directory is used. The SUS mandates for {{mono|du}} the following options:
<code>du</code> takes a single argument, specifying a pathname for {{mono|du}} to work; if it is not specified, the current directory is used. The SUS mandates for {{mono|du}} the following options:
: {{mono|-a}}, In addition to the default output, include information for each non-directory entry
* {{mono|-a}}, In addition to the default output, include information for each non-directory entry
: {{mono|-c}}, display a grand total of the disk usage found by the other arguments
* {{mono|-c}}, display a grand total of the disk usage found by the other arguments
: {{mono|-d #}}, the depth at which summing should occur. -d 0 sums at the current level, -d 1 sums at the subdirectory, -d 2 at sub-subdirectories, etc.
* {{mono|-d #}}, the depth at which summing should occur. -d 0 sums at the current level, -d 1 sums at the subdirectory, -d 2 at sub-subdirectories, etc.
: {{mono|-H}}, calculate disk usage for link references specified on the command line
* {{mono|-H}}, calculate disk usage for link references specified on the command line
: {{mono|-k}}, show sizes as multiples of 1024 [[byte]]s, not 512-byte
* {{mono|-k}}, show sizes as multiples of 1024 [[byte]]s, not 512-byte
: {{mono|-L}}, calculate disk usage for link references anywhere
* {{mono|-L}}, calculate disk usage for link references anywhere
: {{mono|-s}}, report only the sum of the usage in the current directory, not for each directory therein contained
* {{mono|-s}}, report only the sum of the usage in the current directory, not for each directory therein contained
: {{mono|-x}}, only traverse files and directories on the device on which the pathname argument is specified.
* {{mono|-x}}, only traverse files and directories on the device on which the pathname argument is specified.


Other Unix and Unix-like operating systems may add extra options. For example, BSD and GNU <code>du</code> specify a {{mono|-h}} option, displaying disk usage in a format easier to read by the user, adding units with the appropriate [[SI prefix]] (e.g. 10 [[megabyte|MB]]).
Other Unix and Unix-like operating systems may add extra options. For example, BSD and GNU <code>du</code> specify a {{mono|-h}} option, displaying disk usage in a format easier to read by the user, adding units with the appropriate [[SI prefix]] (e.g. 10 [[megabyte|MB]]).
Line 97: Line 98:
{{Disk space analyzers}}
{{Disk space analyzers}}
{{Unix commands}}
{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}
{{Core Utilities commands}}



Latest revision as of 04:44, 2 February 2024

du
Original author(s)Dennis Ritchie
(AT&T Bell Laboratories)
Developer(s)Various open-source and commercial developers
Initial release3 November 1971; 52 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 (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[edit]

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.[1] The command is also available for FreeDOS.[2]

Specification[edit]

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 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[edit]

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

  • -a, In addition to the default output, include information for each non-directory entry
  • -c, display a grand total of the disk usage found by the other arguments
  • -d #, the depth at which summing should occur. -d 0 sums at the current level, -d 1 sums at the subdirectory, -d 2 at sub-subdirectories, etc.
  • -H, calculate disk usage for link references specified on the command line
  • -k, show sizes as multiples of 1024 bytes, not 512-byte
  • -L, calculate disk usage for link references anywhere
  • -s, report only the sum of the usage in the current directory, not for each directory therein contained
  • -x, only traverse files and directories on the device on which the pathname argument is specified.

Other Unix and Unix-like operating systems may add extra options. For example, BSD and GNU du specify a -h 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[edit]

Sum of directories (-s) in kilobytes (-k):

$ du -sk *
152304  directoryOne
1856548 directoryTwo

Sum of directories (-s) in human-readable format (-h : Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte):

$ du -sh *
149M directoryOne
1.8G directoryTwo

disk usage of all subdirectories and files including hidden files within the current directory (sorted by filesize) :

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

disk 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 -h

or 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[edit]

References[edit]

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

External links[edit]