Back to commands

Linux Survival Basics

Read-only, can be slow

Find 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.

next steps

Related commands

Linux Survival Basics Can be slow

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
Web Server Rescue Can be slow

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
Hosting Operations Can be slow

Keep du on One Filesystem

A cleanup scan should not wander into mounted backups or network storage.

du -xh --max-depth=1 /var 2>/dev/null | sort -h
Hosting Operations Can be slow

Review Log Files Before Cleanup

Before truncating logs, prove which log files are large and how old they are.

find /var/log -xdev -type f -printf '%10s %TY-%Tm-%Td %p\n' 2>/dev/null | sort -nr | head -50
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.

  • LPIC-1 style command-line practice
  • LFCS style performance-task practice
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.