Last active
October 20, 2019 12:43
-
-
Save YasienDwieb/d085cb5c206c56fa7f55d48178c34b05 to your computer and use it in GitHub Desktop.
Find largest files or directories
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 | |
if [ $# -eq 0 ] | |
then | |
echo 'Usage:largest.sh file|folder path NUMBEROFRECORDS' | |
exit | |
fi | |
DEST=$2 | |
NUMBEROFRECORDS=10 | |
if [ -n $3 ] | |
then | |
NUMBEROFRECORDS=$3 | |
fi | |
if [ $1 == "file" ] | |
then | |
# find $DEST -type f -exec du -h {} + | sort -rh | head -n $NUMBEROFRECORDS | |
find $DEST -type f -exec du -h {} + | sort -rh | uniq | more | |
elif [ $1 == "folder" ] | |
then | |
# find $DEST -type d -exec du -h {} + | sort -rh | head -n $NUMBEROFRECORDS | |
find $DEST -type d -exec du -h {} + | sort -rh | uniq | more | |
else | |
# du -hS {} + | sort -rh | more | |
find $DEST -type f -exec du -h {} + | sort -rh | uniq | more | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment