Skip to content

Instantly share code, notes, and snippets.

@fletcherist
Created April 1, 2017 20:10
Show Gist options
  • Select an option

  • Save fletcherist/c91c96c2cce970dd359e3a43872b7728 to your computer and use it in GitHub Desktop.

Select an option

Save fletcherist/c91c96c2cce970dd359e3a43872b7728 to your computer and use it in GitHub Desktop.

Revisions

  1. fletcherist created this gist Apr 1, 2017.
    21 changes: 21 additions & 0 deletions dus.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/bash
    dus () {
    size=0
    # checking whether the dir argument provided
    if [ "$1" != "" ]; then
    sub_dir="/$1"
    else
    sub_dir=""
    fi
    # iterating over all files in all subdirectories
    for f in $PWD$sub_dir/**/*
    do
    # checking whether that's the path to the file
    if [[ -f $f ]]; then
    # calculating size in bytes
    tmp=`wc -c "$f" | awk '{print $1}'`
    ((size+=tmp))
    fi
    done
    echo "$size"
    }