Skip to content

Instantly share code, notes, and snippets.

@isa
Last active August 29, 2015 14:09
Show Gist options
  • Save isa/8b80014d99ea0b02d919 to your computer and use it in GitHub Desktop.
Save isa/8b80014d99ea0b02d919 to your computer and use it in GitHub Desktop.
Directory Usage script made pure with Unix functions
#!/bin/sh
find ${1:-.} -type f -exec ls -lnq {} \+ | awk '
function pp() {
u="+Ki+Mi+Gi+Ti";
split(u,unit,"+");
v=sum;
r=0;
for(i=1;i<5;i++) {
if(v<1024) break;
r=v%1024;
v/=1024;
}
printf("%.3f %sB\n",v+r/1024.,unit[i]);
}
{sum+=$5}
END{pp()}'
# captured from http://superuser.com/questions/602818/how-to-get-the-actual-directory-size-out-of-du
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment