How to find what is eating your Disk Space on Linux with du and ncdu

Configurare noua (How To)

Situatie

When a Linux server or PC runs out of space, you need to find the largest folders and files quickly.

Requirements: terminal access with sudo privileges.

Solutie

  1. Check overall usage per filesystem:
df -h
  1. List the biggest top-level folders (the -x option stays on one filesystem):
sudo du -xh / --max-depth=1 2>/dev/null | sort -hr | head -15
  1. Go deeper into the largest folder, for example /var:
sudo du -xh /var --max-depth=1 2>/dev/null | sort -hr | head -15
  1. Find individual files larger than 500 MB:
sudo find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null
  1. For an interactive view, install and run ncdu:
sudo apt install ncdu
sudo ncdu -x /

Use the arrow keys to navigate, press d to delete the selected item (after confirmation) and q to quit.

  1. Clean common space hogs on Debian/Ubuntu:
sudo apt clean
sudo journalctl --vacuum-size=200M
  1. Run df -h again to confirm the space was recovered.

Warning: never delete files from /etc, /usr or /boot unless you know exactly what they are.

Tip solutie

Permanent

Voteaza

(0 din 0 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?