Linux Survival Basics
Read-only, can be slowFind Which Folder Is Filling the Disk
A server is low on disk and you need a folder-level view before drilling into individual files.
Command
du -sh /var/* 2>/dev/null | sort -h
Before you run this
System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.
When not to use it: Avoid assuming the largest folder is safe to delete; size is not ownership or importance. Scope the path more tightly on busy systems.
Expected output
A sorted list of directory sizes under `/var`, often pointing you toward logs, caches, backups, or application data.
System impact
Read-only, can be slow. Nothing changes on disk. The command prints human-readable folder sizes and sorts them.
May require elevated permissions on protected paths or service-owned files.
Scope this to the smallest useful path or service on busy systems.
When to use it
Use this before deeper `find` searches or cleanup decisions. It is a broad map, not the cleanup step.
When not to use it
Avoid assuming the largest folder is safe to delete; size is not ownership or importance. Scope the path more tightly on busy systems.
Recovery / rollback
No filesystem state is changed. If the scan is too slow, stop it with Ctrl-C and rerun against a narrower path.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 19G 5G 80% /work
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/vda1 25G 19G 5G 80% /work
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
$ du -sh /var/* 2>/dev/null | sort -h
64K /var/backups
96K /var/log
192K /var/cache
$ du -sh /var/log /var/cache /var/backups 2>/dev/null
96K /var/log
192K /var/cache
64K /var/backups
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
df -hdu -sh /var/* 2>/dev/null | sort -hdu -sh /var/log /var/cache /var/backups 2>/dev/null
next steps
Related commands
Find the Files Eating Your Disk
The disk was full, but guessing at folders was the slow part.
find /var -type f -printf '%s %p\n' | sort -nr | head -20
Find Large Directories with du
Once you know a filesystem is full, the next question is where.
du -xh --max-depth=1 /var 2>/dev/null | sort -h
Keep du on One Filesystem
A cleanup scan should not wander into mounted backups or network storage.
du -xh --max-depth=1 /lab/disk-inode-cleanup/var 2>/dev/null | sort -h
Check Inodes When Disk Space Looks Fine
Sometimes the disk has free bytes but still cannot create files.
df -ih
Review Log Files Before Cleanup
Before truncating logs, prove which log files are large and how old they are.
find /lab/disk-inode-cleanup/var/log -xdev -type f -printf '%10s %TY-%Tm-%Td %p\n' | sort -nr
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Useful for
- LPIC-1 style command-line practice
- LFCS style performance tasks
- Linux+ style troubleshooting review
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.