du
Files and directories
Usage
du -sh [path]Adds up the disk space files actually occupy; it counts allocated blocks, so its total differs from the sum of file sizes and from df.
Common flags
| Flag | Meaning |
|---|---|
| -s | One total per argument instead of every subdirectory |
| -h | Readable sizes such as 1.2G |
| -a | Include files, not only directories |
| -d | Limit the depth; GNU also spells it --max-depth |
| -x | Stay on one filesystem |
| -c | Print a grand total at the end |
Examples
du -sh *Size of every item in this directory.
du -h -d 1 / | sort -hTop-level directories, smallest to biggest.
du -shx /varSize of /var without crossing into other mounts.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does du do?
Adds up the disk space files actually occupy; it counts allocated blocks, so its total differs from the sum of file sizes and from df.
Q. How do I type it?
du -sh [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man du. This command sits under Files and directories.
Related commands
man page: man du