Linux Disk Usage and Management — df, du, lsblk, and Cleaning Up Space

Linux Disk Usage and Management — df, du, lsblk, and Cleaning Up Space

Derrk SamuelJune 6, 20266 min read
Running out of disk space on a Linux server is a silent killer. Learn how to check disk usage, find what's consuming space, identify large files and directories, and clean up safely.

Linux Disk Usage and Management

Running out of disk space on a Linux server or blockchain node host is one of the most common — and avoidable — problems.


Check Overall Disk Space

df — Disk Free

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       100G   82G   18G  82% /

List Block Devices and Partitions

lsblk
lsblk -f   # Adds filesystem type and UUID

Find What's Eating Your Disk

du — Disk Usage

du -sh /var/log                          # Size of a specific directory
du -h --max-depth=1 /var | sort -hr     # Top directories by size
du -h / --max-depth=4 2>/dev/null | sort -hr | head -10   # Top 10 largest

Find Large Files

find / -type f -size +1G 2>/dev/null        # Files over 1GB
find /var -type f -size +500M 2>/dev/null   # Files over 500MB in /var

Clean Up Common Space Hogs

APT Package Cache

sudo apt clean
sudo apt autoremove

Old Log Files

sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=7d

Docker Cleanup

docker system df          # See how much Docker is using
docker system prune       # Remove all unused Docker objects
docker system prune --volumes   # Include unused volumes

Truncate a Specific Log File

sudo truncate -s 0 /var/log/syslog

Interactive Disk Browser — ncdu

sudo apt install ncdu
ncdu /

Navigate with arrow keys, press d to delete. One of the most useful tools for disk management on Linux.


Quick Reference

GoalCommand
Overall disk spacedf -h
List block deviceslsblk
Directory sizedu -sh /path
Top dirs by size`du -h --max-depth=1 /path
Find files over 1GBfind / -type f -size +1G
Clean APT cachesudo apt clean && sudo apt autoremove
Clean journal logssudo journalctl --vacuum-size=500M
Clean Dockerdocker system prune
Interactive browserncdu /
D

Derrk Samuel

Web3, crypto, and Linux PC insights — practical guides, security tips, mining setups, blockchain tools, and decentralized tech strategies for techs.

Discussion

Leave a comment

No comments yet. Be the first to start the discussion!