Skip to content

Instantly share code, notes, and snippets.

@cybertk
Last active Jun 1, 2017
Embed
What would you like to do?
List directories sorted by size, find largest directories
#!/usr/bin/env bash
# List directories sorted by size, find largest directories
# Author: Quanlong <kyan.ql.he@gmail.com>
# Version: v20170601
#
# Upgrade with curl -o https://gist.githubusercontent.com/cybertk/4b02531350c09235f3e2d00fdbb3bbcd/raw/36ebae4da87ea7fe504ba58c32c81060c62e6b8d/largest
list_dir_by_size() {
declare dir="$1"
echo "$dir"
find "$dir" -type d -depth 1 -print0 | xargs -0 du -hs | gsort -hr
}
usage() {
echo "largest <path_of_dir>"
echo ""
echo "List directories sorted by size"
}
main() {
if [[ "$1" = "--help" || "$1" = "-h" ]]; then
usage
exit 1
fi
list_dir_by_size "${1:-$(pwd)}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment