WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script disk-usage-report

Disk Usage Report

Show filesystem usage and the largest directories under a path.

category System Administration shell Bash 4+ updated 2026-08-21
diskdudfreport
Safety notes

No destructive commands are used by this script, but review it before running.

Dependencies: df, du, sort

Usage

  • Pass the directory to inspect (default: current directory).
  • Set TOP to change how many directories are listed (default 10).

Script

#!/usr/bin/env bash
set -euo pipefail

target="${1:-.}"
top="${TOP:-10}"

[[ -d "$target" ]] || { echo "not a directory: $target" >&2; exit 1; }

echo "== filesystems =="
df -h -x tmpfs -x devtmpfs

echo
echo "== top ${top} directories under ${target} =="
du -x -h --max-depth=1 "$target" 2>/dev/null \
  | sort -h \
  | tail -n "$top"

Example

./disk-usage-report /var
TOP=20 ./disk-usage-report /home

Notes

  • du -x stays on one filesystem, so mounted volumes are not counted twice.
  • A permission error usually means the script needs to run with sudo for a complete picture.

Related scripts

Safe Log Cleanup

Delete rotated log files older than a set number of days, with a dry-run first.

System Administration

Disk Threshold Alert

Exit non-zero when any mounted filesystem exceeds a usage threshold.

Monitoring

Find Large Files

Locate files above a size threshold and show them largest first.

File Management