Skip to content

Instantly share code, notes, and snippets.

@cybertk
Last active June 1, 2017 07:51
Show Gist options
  • Save cybertk/4b02531350c09235f3e2d00fdbb3bbcd to your computer and use it in GitHub Desktop.
Save cybertk/4b02531350c09235f3e2d00fdbb3bbcd to your computer and use it in GitHub Desktop.
List directories sorted by size, find largest directories
#!/usr/bin/env bash
# List directories sorted by size, find largest directories
# Author: Quanlong <[email protected]>
# 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