Linux for Developers Course
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 / OptionDescription
-hHuman-readable sizes.
-sSummarize. Display only a total for each argument.
-aWrite 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`?

Flash Cards

Question

What happens?

Click to reveal answer
Answer

It will recursively print the exact size of every single file and folder on the entire computer, scrolling thousands of lines across your screen indefinitely.

Question

What is -s?

Click to reveal answer
Answer

Summarize. Instead of printing the size of every individual file inside a folder, it just prints one single grand total size for the folder itself.