Skip to content

Instantly share code, notes, and snippets.

@josephwb
Created June 7, 2018 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephwb/61a89b36bb67fe5f895e1cb641a89a46 to your computer and use it in GitHub Desktop.
Save josephwb/61a89b36bb67fe5f895e1cb641a89a46 to your computer and use it in GitHub Desktop.
Recursively find large files
#!/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