Created
November 18, 2021 13:52
-
-
Save blokhin/72692e7bde5f539ec02623c82ca71c9f to your computer and use it in GitHub Desktop.
Get exact size of directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
find ${1:-.} -type f -exec ls -lnq {} \+ | awk ' | |
BEGIN {sum=0} # initialization for clarity and safety | |
function pp() { | |
u="+Ki+Mi+Gi+Ti+Pi+Ei"; | |
split(u,unit,"+"); | |
v=sum; | |
for(i=1;i<7;i++) { | |
if(v<1024) break; | |
v/=1024; | |
} | |
printf("%.3f %sB\n", v, unit[i]); | |
} | |
{sum+=$5} | |
END{pp()}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment