du cheat sheet
Basic options
Long option | Short option | What the option does |
---|---|---|
--human-readable | -h | Show size in human readable format, such as kilobytes and megabytes |
--max-depth=NUMBER | -d | Set a maximum depth to summary, useful to see size of a particular directory |
--summarize | -s | Don’t show all files or directories, but summarize the output |
--threshold=-VAL | -t | Files smaller than VAL |
--time | Show the last modification time of any file or a sub directory in the specified directory |
Creating a shell script? Then we suggest using the long format option, as this improves the readability. For quick use of on the command-line consider using the short notation of the related option.
Show size for a single directory
By setting a max-depth of zero, we can see the size of a particular directory.
du --human-readable --max-depth=0 /var
An alternative is using the --summarize
Files by a minimum size
Only see files smaller than 1 megabyte.
du --human-readable --threshold=-1M /var
To show all files bigger than a specified size, use the threshold with a positive number. For example, all files bigger than 10 megabyte:
du --human-readable --threshold=10M /var