Linux Survival Basics
Find the Files Eating Your Disk
A machine is low on disk space and you need to quickly find the largest files under a path.
Command
find /var -type f -printf '%s %p\n' | sort -nr | head -20
What changed
Nothing changes. The command lists large files so cleanup is based on evidence.
Danger
safe
When to use it
Use this before deleting logs, caches, backups, or uploads.
When not to use it
Avoid running broad searches on extremely busy systems without considering IO impact.
Undo or recovery
No state is changed.
Expected output
A sorted list of byte sizes and file paths.
demo script
Disposable terminal steps
df -hdu -sh /var/* 2>/dev/null | sort -hfind /var -type f -printf '%s %p\n' | sort -nr | head -20
simulated output
What it looks like
::fixture-ready::
$ df -h
Filesystem Size Used Avail Use% Mounted on
overlay 3.6T 1.2T 2.3T 35% /
tmpfs 64M 0 64M 0% /dev
shm 64M 0 64M 0% /dev/shm
tmpfs 64M 0 64M 0% /tmp
tmpfs 64M 352K 64M 1% /var
/dev/nvme0n1p2 3.6T 1.2T 2.3T 35% /lab/demo.sh
tmpfs 63G 0 63G 0% /proc/asound
tmpfs 63G 0 63G 0% /proc/acpi
tmpfs 63G 0 63G 0% /proc/scsi
tmpfs 63G 0 63G 0% /sys/firmware
tmpfs 63G 0 63G 0% /sys/devices/virtual/powercap
::exit-code::0
$ du -sh /var/* 2>/dev/null | sort -h
64K /var/backups
96K /var/log
192K /var/cache
::exit-code::0
$ find /var -type f -printf '%s %p\n' | sort -nr | head -20
196608 /var/cache/demo/blob.cache
98304 /var/log/app.log
65536 /var/backups/site.tar
::exit-code::0
YouTube Short
Find the files eating your disk.
Do not start deleting random folders. First list the largest files, then decide what is actually safe to remove.
LinkedIn hook
The disk was full, but guessing at folders was the slow part.
Question: What is the first disk-space command you usually run?
experiments
A/B tests to run
Metric: linkedin_comment_rate
A: The disk was full, but guessing at folders was the slow part.
B: This is the command I run before deleting anything.