Resources and networking

Inspect disk and memory

Distinguish filesystem capacity, directory usage, RAM pressure, and swap before deciding what resource is exhausted.

8 minute lesson

~~~

Disk capacity and memory pressure are different problems. Diagnose the resource that is actually exhausted before deleting files or restarting services.

Filesystem capacity

Use df to inspect mounted filesystems:

df -h
df -ih

df -h reports byte capacity. df -ih reports inodes, the filesystem records used for files and directories. A filesystem can have free gigabytes but no free inodes after creating millions of tiny files.

Find large top-level directories without crossing into other mounted filesystems:

sudo du -xhd1 /var | sort -h

Move deeper only into the large area you found. Do not start by deleting /var/log or /var/lib; active logs and database files may live there.

If df shows full space but du cannot account for it, check for deleted files still held open:

sudo lsof +L1

The space returns when the owning process closes the file. Restart that service only after you understand the impact.

Memory and swap

Use:

free -h

Linux uses otherwise idle RAM for filesystem cache. Low free memory alone is not an emergency. The available estimate is more useful because it includes memory the kernel can reclaim.

Swap use is also not automatically a failure. Look for sustained swapping, slow responses, out-of-memory messages, and a process whose memory keeps growing.

Inspect the largest processes:

ps -eo pid,user,%mem,rss,comm --sort=-rss | head

Then correlate the process with application metrics and logs. A database using memory for a configured cache may be healthy; an unknown worker growing without limit may not be.

Verify the fix

After cleanup or a service change, rerun the same commands and test the application. Record what freed the resource so the problem can be prevented with rotation, limits, alerts, or capacity changes.

Try this: inspect a test machine with df -h, df -ih, du, and free -h. Write one sentence explaining what each command can prove.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →