Skip to content

Instantly share code, notes, and snippets.

@YasienDwieb
Last active October 20, 2019 12:43
Show Gist options
  • Save YasienDwieb/d085cb5c206c56fa7f55d48178c34b05 to your computer and use it in GitHub Desktop.
Save YasienDwieb/d085cb5c206c56fa7f55d48178c34b05 to your computer and use it in GitHub Desktop.
Find largest files or directories
#!/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