What if you could instantly see which folders are secretly eating up all your disk space?
Why du (disk usage by directory) in Linux CLI? - Purpose & Use Cases
Imagine you have a cluttered closet with many boxes, and you want to find out which boxes take up the most space. Without a tool, you would have to open each box, measure its contents, and write down the sizes manually.
Doing this by hand is slow and tiring. You might forget some boxes or make mistakes measuring. It's hard to keep track, and you waste time just trying to figure out where your space is going.
The du command quickly checks the size of every folder and subfolder for you. It shows you exactly how much space each directory uses, so you can spot the biggest space hogs instantly without opening anything.
open folder1; check size; write down; open folder2; check size; write down; ...
du -h --max-depth=1With du, you can easily find and manage disk space, keeping your system clean and efficient.
When your computer warns you that the disk is almost full, you can run du to quickly find which folders are using the most space and decide what to delete or move.
Manually checking folder sizes is slow and error-prone.
du automates disk usage checks, saving time and effort.
This helps keep your storage organized and prevents surprises.
Practice
du command primarily show in Linux?Solution
Step 1: Understand the purpose of
Theduducommand stands for disk usage and shows how much space files and directories use.Step 2: Compare options
Options B, C, and D relate to other commands likelsorps, notdu.Final Answer:
The disk space used by files and directories -> Option AQuick Check:
du= disk space used [OK]
- Confusing du with ls or ps commands
- Thinking du shows file counts
- Assuming du shows current directory path
du command option shows sizes in a human-readable format?Solution
Step 1: Identify the option for human-readable sizes
The-hoption makes sizes easier to read by adding units like K, M, G.Step 2: Understand other options
-ssummarizes,-ashows all files,-cadds a total line.Final Answer:
-h -> Option DQuick Check:
-h= human-readable sizes [OK]
- Using -s expecting human-readable sizes
- Confusing -a or -c with size formatting
- Omitting the -h option for readability
du -sh /var/log if the /var/log directory uses 120M of disk space?Solution
Step 1: Understand the command options
-ssummarizes total size,-hshows human-readable format.Step 2: Predict output format
The output shows size with unit, a tab, then directory path: "120M\t/var/log".Final Answer:
120M /var/log -> Option BQuick Check:
du -sh output = size + tab + path [OK]
- Omitting the tab separator
- Writing size without unit
- Showing size without path
du -h /home/user but get an error: "du: invalid option -- 'h'". What is the likely cause?Solution
Step 1: Analyze the error message
The error says-his invalid, meaning thisduversion lacks that option.Step 2: Check other options
Running as root or directory existence wouldn't cause invalid option error;-his standard, no need for long form.Final Answer:
Theducommand does not support the-hoption on this system -> Option CQuick Check:
Invalid option error means unsupported flag [OK]
- Assuming permission or path errors cause invalid option
- Trying --human-readable instead of checking version
- Ignoring error message details
/home/user but only see sizes for individual files. Which command correctly summarizes each subdirectory size in human-readable form?Solution
Step 1: Understand the goal
You want sizes of each subdirectory summarized, not individual files.Step 2: Analyze options
du -ahshows all files and dirs,du -shon directory alone summarizes total only,du -sno human-readable.du -sh /home/user/*summarizes each subdirectory separately in human-readable form.Final Answer:
du -sh /home/user/* -> Option AQuick Check:
Use du -sh with wildcard for each subdir [OK]
- Using -a to include files instead of just dirs
- Using -s alone for total only
- Not using wildcard to list subdirectories
Ready to prove it?
Pass the test and this pattern moves unknown
