Created
March 24, 2025 12:22
-
-
Save OhadRubin/725154b8952c526de96ab357b0878b65 to your computer and use it in GitHub Desktop.
find_largest.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dirs=($(sudo du -h --max-depth=1 ~/ | sort -h | awk '{print $2}' | tail -n 10 | head -n 9)) | |
for dir in "${dirs[@]}"; do | |
if [ ! -d "$dir" ]; then | |
echo "Warning: $dir is not a directory or doesnt exist" | |
continue | |
fi | |
echo "Largest file in $dir:" | |
find "$dir" -type f -printf "%s %p\n" 2>/dev/null | sort -nr | head -n1 | awk '{printf "%.2f MB (%d bytes): %s\n", $1/1024/1024, $1, substr($0, length($1)+2)}' | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment