csot/contest

Task 10 — Disk usage, top 10 directories

Write a script 10.sh that reports the largest directories under a given root, up to 10 lines.

Submit as

10.sh

Input

Source Format
CLI ./10.sh <dir> — directory to measure
Filesystem Immediate subdirectories (and nested dirs as du reports them). Permission errors on unreadable paths should be suppressed, not fatal.

Output

Stream Format
stdout At most 10 lines. Each line: <size_in_KiB><TAB><path>
<size_in_KiB> — integer, kilobyte blocks (same units as du -k)
<path> — directory path as printed by du
Lines sorted by size descending (largest KiB first)
stderr Not checked (redirect permission errors away with 2>/dev/null if needed)
Exit code 0 on success

Example

./10.sh /var

stdout (sample):

1048576 /var/lib
524288  /var/lib/docker
262144  /var/cache
131072  /var/log
65536   /var/lib/apt

What the grader checks

  • Exit code 0
  • Between 5 and 10 lines of output
  • First column is numeric and non-increasing (sorted descending)
  • Largest line is at least 2048 KiB (fixture tree uses large dirs)

Exact paths are not compared; sort order and scale matter.

Hints

  • du -k — KiB blocks
  • sort -rn then head -10
  • 2>/dev/null on du to hide “Permission denied”

Points: 5

Other tasks