0
0
Linux CLIscripting~20 mins

du (disk usage by directory) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Disk Usage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this du command?
You run the command du -sh /var/log on a Linux system. What does the output represent?
Linux CLI
du -sh /var/log
AThe total disk space used by the /var/log directory and all its contents, shown in a human-readable format.
BThe free disk space available on the partition containing /var/log.
CThe number of files inside /var/log directory.
DThe size of the largest file inside /var/log.
Attempts:
2 left
💡 Hint
Think about what the options -s and -h mean in the du command.
💻 Command Output
intermediate
1:30remaining
What does this command output?
You run du -h --max-depth=1 /home/user. What will the output show?
Linux CLI
du -h --max-depth=1 /home/user
AOnly the total disk usage of /home/user without details.
BDisk usage of all files inside /home/user recursively, one line per file.
CDisk usage of /home/user and each of its immediate subdirectories, in human-readable form.
DDisk usage of /home/user but excluding hidden files.
Attempts:
2 left
💡 Hint
The --max-depth=1 limits how deep du reports.
🔧 Debug
advanced
1:30remaining
Why does this du command fail?
You try to run du -h --maxdepth=1 /etc but get an error. What is the cause?
Linux CLI
du -h --maxdepth=1 /etc
AThe option should be spelled <code>--max-depth</code> with a hyphen, not <code>--maxdepth</code>.
BThe directory /etc does not exist.
CThe <code>-h</code> option cannot be combined with <code>--maxdepth</code>.
DYou need root permissions to run du on /etc.
Attempts:
2 left
💡 Hint
Check the spelling of the option carefully.
🚀 Application
advanced
2:00remaining
How to find the top 3 largest subdirectories in /var?
You want to list the three largest subdirectories inside /var by disk usage. Which command will do this?
Adu -sh /var/* | sort -h | tail -n 3
Bdu -h /var | sort -h | head -n 3
Cdu -sh /var | sort -hr | head -n 3
Ddu -h --max-depth=1 /var | sort -hr | head -n 3
Attempts:
2 left
💡 Hint
Use du with max-depth to get sizes of immediate subdirectories, then sort and pick top 3.
🧠 Conceptual
expert
2:00remaining
What is the effect of using du -b compared to du -h?
You run du -b /tmp and du -h /tmp. What is the difference in their outputs?
A<code>du -b</code> shows sizes in bits, <code>du -h</code> shows sizes in bytes.
B<code>du -b</code> shows disk usage in bytes (exact number), while <code>du -h</code> shows sizes in human-readable units like KB or MB.
C<code>du -b</code> shows sizes rounded to nearest KB, <code>du -h</code> shows exact bytes.
D<code>du -b</code> shows block counts, <code>du -h</code> shows bytes.
Attempts:
2 left
💡 Hint
Think about what the -b and -h options mean for size units.