What I Wanted to Do
I wanted to check disk usage on a Linux server. Using df and du, you can check the disk free space and folder sizes.
df: Check Overall Disk Usage
df -h # Display in human-readable format
df -h / # Show root only
df -h /var # Specify a particular path
Example output
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
du: Check Folder Size
du -sh foldername # Total size of a folder
du -sh /* # Each folder directly under root
du -sh /var/log/* # Contents of the log folder
du -h --max-depth=1 /var # Show only one level deep
Handling a Full Disk
Find large files
find / -size +100M -type f 2>/dev/null
Delete log files
sudo journalctl --vacuum-size=100M # Trim systemd logs to 100MB or less
sudo find /var/log -name "*.log" -mtime +30 -delete # Delete logs older than 30 days
Remove unused Docker data
docker system prune -a
Common Pitfalls
dfchecks the whole filesystem;duchecks a specific folder’s size- The
-hoption displays sizes in human-readable format (GB/MB) - When using Docker,
/var/lib/dockertends to grow large
If your VPS is running low on RAM, you can ease memory pressure by adding swap space using How to Set Up Swap on Linux.
Related Articles
- Essential Linux Commands (ls/cd/mkdir/rm) Cheat Sheet
- How to Monitor Logs in Real Time with tail -f on Linux
- Docker Basic Commands Cheat Sheet
- How to Set Up Docker on a VPS for Production
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers