Linux Terminal Command: du

The du command is an essential tool in System Information & Hardware. In this tutorial, we will explore what du does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The du command calculates the disk space occupied by specific directories and files recursively.


Common Options & Syntax

du [options] [arguments]

Here are the most common flags used with du:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
du -sh ./folder

What it does: Displays the total combined size of ‘./folder’ in a human-readable format.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
du -ah --max-depth=2 /var/log | sort -rh | head -n 10

What it does: Finds all files and folders in /var/log up to 2 directories deep, sorts them by size in descending order, and displays the top 10 space consumers.


⚙️ Warning & Common Pitfalls

[!WARNING] Running du on root directories (/) can take a long time because it must read metadata for every single file. Use --max-depth to restrict the search depth.


Here are some related posts on cli_tty1 you might want to check out: