Skip to content

Instantly share code, notes, and snippets.

@fletcherist
Created April 1, 2017 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fletcherist/c91c96c2cce970dd359e3a43872b7728 to your computer and use it in GitHub Desktop.
Save fletcherist/c91c96c2cce970dd359e3a43872b7728 to your computer and use it in GitHub Desktop.
#!/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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment