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.

Revisions

  1. cybertk renamed this gist Jun 1, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt → largest
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Author: Quanlong <[email protected]>
    # Version: v20170601
    #
    # Upgrade with
    # Upgrade with curl -o https://gist.github.com/cybertk/4b02531350c09235f3e2d00fdbb3bbcd/raw/36ebae4da87ea7fe504ba58c32c81060c62e6b8d/largest

    list_dir_by_size() {
    declare dir="$1"
  2. cybertk created this gist Jun 1, 2017.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/env bash

    # List directories sorted by size, find largest directories
    # Author: Quanlong <[email protected]>
    # Version: v20170601
    #
    # Upgrade with

    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 "$@"