Bash

Find Largest Files and Directories

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Quick "where did all my disk go?" answer. du sorts by size, ncdu (interactive) is better for exploration.
Bash
Raw
# Top 20 largest files under a path
find /var -type f -printf '%s\t%p\n' 2>/dev/null | sort -rn | head -20 | numfmt --to=iec --field=1

# Top 10 largest directories at one level deep
du -sh /var/* 2>/dev/null | sort -rh | head -10

# Recursive top-N (slower — finds the biggest leaf dirs)
du -ah /var 2>/dev/null | sort -rh | head -20

# Interactive — best UX for exploration (must be installed)
ncdu /var

# Largest files older than 30 days (good cleanup candidates)
find / -type f -mtime +30 -printf '%s\t%TY-%Tm-%Td\t%p\n' 2>/dev/null \
    | sort -rn | head -20 | numfmt --to=iec --field=1
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.