@@ -0,0 +1,37 @@ | |||||
#!/bin/bash | |||||
# Format size in bytes into a readable string of the form "1.23 KiB"; reads from stdin and arguments and can take multiple numbers separated by any amount of whitespace including newlines | |||||
{ | |||||
if [ ! -t 0 ]; then cat; fi | |||||
echo "$@" | |||||
} | | |||||
tr '\t ' '\n' | | |||||
awk ' | |||||
BEGIN { | |||||
units[0] = "B"; | |||||
units[1] = "KiB"; | |||||
units[2] = "MiB"; | |||||
units[3] = "GiB"; | |||||
units[4] = "TiB"; | |||||
units[5] = "PiB"; | |||||
} | |||||
{ | |||||
size += $1; | |||||
} | |||||
END { | |||||
if (size > 0) { | |||||
magnitude = int(log(size) / log(1024)); | |||||
if (magnitude > 5) { | |||||
magnitude = 5; | |||||
} | |||||
} else { | |||||
magnitude = 0; | |||||
} | |||||
if (magnitude > 0) { | |||||
sizeformat = "%.2f"; | |||||
} else { | |||||
sizeformat = "%d"; | |||||
} | |||||
printf sizeformat " %s\n", size / (1024 ^ magnitude), units[magnitude]; | |||||
}' |
@@ -1,3 +1,3 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
# Total size of all WARCs in the current directory (or subdirectories) | # Total size of all WARCs in the current directory (or subdirectories) | ||||
find -name '*.warc.gz' -printf '%s\n' | awk 'BEGIN { units[0] = "B"; units[1] = "KiB"; units[2] = "MiB"; units[3] = "GiB"; units[4] = "TiB"; units[5] = "PiB"; } { size += $1 } END { if (size > 0) { magnitude = int(log(size) / log(1024)); if (magnitude > 5) { magnitude = 5; } } else { magnitude = 0; } if (magnitude > 0) { sizeformat = "%.2f"; } else { sizeformat = "%d"; } printf sizeformat " %s\n", size / (1024 ^ magnitude), units[magnitude]; }' | |||||
find -name '*.warc.gz' -printf '%s\n' | "$(cd "$(dirname "$0")"; pwd -P)/format-size" |