Linux for Developers
/Intermediate
du
Definition
Disk Usage. A command used to estimate and display the exact file space usage of a specific directory and its subdirectories.
Explain Like I'm New
The 'Which folder is eating all my space?' command. It calculates the exact size of every folder inside a directory.
Real World Example
You know the hard drive is 99% full, but you don't know why. You navigate to the root directory and type `du -sh *`. It summarizes the size of every folder, revealing that the `/var/logs` folder is inexplicably 500 Gigabytes.
Common Use Cases
- •Finding large hidden files
- •Freeing up disk space
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| -h | Human-readable sizes. |
| -s | Summarize. Display only a total for each argument. |
| -a | Write counts for all files, not just directories. |
Interview Questions
basic
- If you run `du` without any flags on the root `/` directory, what happens?
intermediate
- What does the `-s` flag do in `du -sh`?