Du (Unix)
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.
differs from
df in that reports size information of file system items whereas reports statistics about the storage media as a whole. 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, might report more allocated space than 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. The implementation in GNU coreutils was written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering. The command is also available for FreeDOS. A similar command is available for Windows in Sysinternals by Mark Russinovich.Use
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:- : In addition to the default output, include information for each non-directory entry
- : Report the grand total of the storage usage for the specified scope
- : 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
- : Calculate storage usage for link references specified on the command line
- : Show sizes as multiples of 1024 bytes, not 512-byte
- : Calculate storage usage for link references
- : Report only the sum of the usage of the starting scope directory, and not that of subdirectories
- : Only traverse files and directories on which the path argument is specified
Examples
Report the storage use for each file and directory tree in kilobytes :$ du -sk *
152304 directoryOne
1856548 directoryTwo
Report the storage use in a more human-readable format with a sum total at the end, formatted as human-readable :
$ du -d 1 -c -h
For the GNU implementation, is used instead of.
Report the storage use under the root directory with a sum total at the end, formatted as human-readable without traversing into other file systems. Useful when /var, /tmp or other directories are on separate storage from the root directory:
$ du -d 1 -c -h -x /