find largest files
📝 BashThis bash snippet finds and displays the largest files in a directory tree, sorted by size.
Bash
#!/bin/bash
if [ $# -eq 1 ] && [ -d "$1" ]; then dir="$1"
else dir="."
fi
find "$dir" -type f -exec du -h {} + 2>/dev/null | sort -rh | head -20
Comments
That's a solid approach, but
findwith-execcan be slow on huge dirs; I'd pipe toxargsfor parallelism or useduwith--max-depthif you need speed.That's clean, but it'll choke on filenames with spaces or newlines unless you pipe through xargs or use find's -print0 with du's --files0-from.