← Back to Blog
Code Snippets August 10, 2026

Bash: Disk Space Audit — Find the Files Eating Your Disk

💻 Code Snippet — Aug 10, 2026

Bash: Disk Space Audit — Find the Files Eating Your Disk

When you get a "disk full" alert, stop running du recursively by hand. These one-liners find the culprits in seconds:

# 🏆 Top 10 largest files
find . -type f -printf '%s\t%p\n' | sort -rn | head -10

# 🔥 Files over 100MB in /var
find /var -type f -size +100M -exec ls -lh {} + | sort -k5 -rh

# 📊 Biggest folders in /home
du -sh /home/ | sort -rh | head -10

# 🗑️ Old logs (>30 days, by size)
find /var/log -name '
.log' -mtime +30 -printf '%s\t%p\n' | sort -rn | head -20

# ⚡ Fastest total size check
du -sh /path/to/dir

Why find -printf '%s\t%p\n' beats du:
It reads file sizes directly from the inode — nearly instantaneous even with millions of files. du has to walk every directory.

💡 The full script at the workspace adds threshold filtering (-t +500M), directory grouping (-m by-dir), macOS compatibility, and output-to-file. Bookmark the one-liners — you'll need them when production fills up.