Estimate disk space usage (POSIX)
du [-a|-s] [-ikpqx] [file...]
The du utility prints the size of the file space allocated to the specified files. If you name a directory, all files in that directory are reported; subdirectories are traversed recursively. If a file has multiple links, the space allocated to that file is counted only once.
The du utility doesn't take into account the filesystem space taken up by persistent pregrown files, i.e. files which have had space in excess of the file size pre-allocated in anticipation of future growth. Pregrowing is often done by the filesystem for files which have been appended to. Filesystems prior to 4.24 didn't support this feature. When using current filesystems which do support persistent pregrown files, you can disable this feature by mounting the disk with the mount utility's -g flag. |
The space figures are displayed in 512-byte blocks by default. If you want du to print the size in bytes, you specify the -p option. The sizes output by du when you specify the -p option are accurate with one exception. The numbers may be slightly higher than expected because they include extent blocks that are part of filesystem overhead associated with the file, but don't contain actual data.
If you specify nondirectories, they aren't listed unless you specify the -a option.
Files with multiple links are reported only once.
Estimate disk space consumed by the contents of /tmp, in kbytes:
du -k /tmp
Estimate the total space occupied by the contents of the current directory:
du -s
All results are written to the standard output. Errors may result in diagnostic messages to the standard error. Standard input isn't used.
The du utility will obtain directory information pertaining to the file(s) and directories named on the command line and, for each file that is a directory, will recurse through the filesystem obtaining directory information about the files and directories contained therein.