Skip to content

Instantly share code, notes, and snippets.

@mlegenhausen
Created March 5, 2014 11:24
Show Gist options
  • Save mlegenhausen/9365461 to your computer and use it in GitHub Desktop.
Save mlegenhausen/9365461 to your computer and use it in GitHub Desktop.
Get directory size via the command line on mac os and linux in a human readable format
#!/bin/sh
find $1 -type f -print0 | xargs -0 stat -f'%z' | awk '{b+=$1} END {print b}' | awk '{ sum=$1 ; hum[1024**3]="Gb";hum[1024**2]="Mb";hum[1024]="Kb"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment