Created
June 7, 2018 09:10
-
-
Save josephwb/61a89b36bb67fe5f895e1cb641a89a46 to your computer and use it in GitHub Desktop.
Recursively find large files
This file contains 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 | |
# report files greater than some size (default 100 MB) | |
# does so recursively starting at some dir (default pwd) | |
# to make executable, do: | |
# chmod +x find_large_files.sh | |
print_help () { | |
echo "Recursively find all files larger than some size" | |
echo "Usage:" | |
echo " -d STARTING_DIR (default pwd)" | |
echo " -s MIN_FILE_SIZE_IN_MB (default 100)" | |
exit 0 | |
} | |
while getopts "d:s:h" opt; do | |
case $opt in | |
h) print_help ;; | |
d) DIR="$OPTARG" ;; | |
s) SIZE="$OPTARG" ;; | |
\?) echo "Invalid option -$OPTARG" >&2 ;; | |
esac | |
done | |
if [ -z "$DIR" ]; then | |
DIR=$PWD | |
fi | |
if [ -z "$SIZE" ]; then | |
SIZE=100M | |
else | |
SIZE=$SIZE"M" | |
fi | |
find $DIR -xdev -type f -size +$SIZE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment