How to find large files and free space
Topic: Servers linux
Summary
Use du, find, and ncdu to locate the largest files and directories so you can free disk space or move data. Use this when a filesystem is full or you need to identify what is consuming space before cleanup or resizing.
Intent: How-to
Quick answer
- du -sh /var/* | sort -h shows directory sizes under /var; du -ah /path | sort -rh | head -20 shows largest files. Start from the mount point that is full (df -h).
- find /var -type f -size +100M -exec ls -lh {} \; finds files larger than 100 MiB; adjust -size for your needs. ncdu /var gives an interactive browse of disk usage.
- After finding large files, move, compress, or delete as appropriate; clear package caches (apt clean, dnf clean) and truncate or rotate logs; see disk usage and disk full recovery guides.
Prerequisites
Steps
-
Identify full filesystem
df -h to see which mount is full (e.g. / or /var). Focus du and find on that mount; avoid scanning NFS or removable media if not relevant.
-
Find largest directories and files
du -sh /var/* | sort -h; du -ah /var | sort -rh | head -30. For files over a size: find /var -type f -size +100M -exec ls -lh {} \;. Use ncdu /var for interactive drill-down.
-
Act on findings
Remove or move large files; run apt clean or dnf clean; truncate or rotate logs (see log rotation); clear caches. Re-run df -h and du to confirm space freed.
Summary
Use du, find, and ncdu to find the largest files and directories on a full or crowded filesystem so you can free space. Start from the mount point reported by df -h.
Prerequisites
Steps
Step 1: Identify full filesystem
df -h
Note which mount is full and run du/find under that path.
Step 2: Find largest directories and files
du -sh /var/* | sort -h
find /var -type f -size +100M -exec ls -lh {} \;
Use ncdu for interactive browsing.
Step 3: Act on findings
Delete, move, or compress as appropriate; clean package caches and rotate logs; verify with df and du.
Verification
- You have a list of the largest consumers; space is freed and df -h shows the change.
Troubleshooting
find too slow — Narrow the path; use du first to find heavy directories then find inside them. Permission denied — Run with sudo when scanning system directories.