Managing Disk Space on Your Server

Managing Disk Space on Your Server

Check Overall Disk Usage

df -h

Shows each partition, total size, used space, available space, and mount point. Watch for any partition above 80% usage.

Find Large Directories

du -sh /* 2>/dev/null | sort -rh | head -20

Interactive Disk Usage Browser — ncdu

apt install ncdu -y
ncdu /

Navigate with arrow keys, press d to delete a file or directory, q to quit.

Common Disk Space Culprits

Old log files:

ls -lh /var/log/
journalctl --disk-usage
journalctl --vacuum-size=500M   # Keep only 500 MB of system logs

APT package cache:

apt autoremove -y
apt clean

Docker unused images/containers:

docker system prune -a

Old Linux kernels (Ubuntu):

apt autoremove --purge -y

Monitor Disk Usage Over Time

watch -n 5 df -h

Set Up a Low-Disk Alert

Add this to your crontab to email you when disk usage exceeds 85%:

0 6 * * * df -h | awk '$5+0 > 85 {print}' | mail -s "Disk Alert" you@example.com
  • 0 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

Managing Users and Groups

Managing Users and Groups on Linux Proper user management is essential for server security. Avoid...

Managing Services with systemctl

Managing Services with systemctl systemctl is the standard tool for managing services on modern...

Monitoring Server Resources

Monitoring Server Resources Keeping an eye on your server's resource usage helps you identify...

Scheduling Tasks with Cron

Scheduling Tasks with Cron Cron allows you to schedule commands to run automatically at set...

Installing and Configuring Nginx

Installing and Configuring Nginx Nginx is a high-performance web server and reverse proxy widely...