summaryrefslogtreecommitdiff
path: root/bin/format-bytes
diff options
context:
space:
mode:
Diffstat (limited to 'bin/format-bytes')
-rwxr-xr-xbin/format-bytes11
1 files changed, 11 insertions, 0 deletions
diff --git a/bin/format-bytes b/bin/format-bytes
new file mode 100755
index 0000000..0e2e32d
--- /dev/null
+++ b/bin/format-bytes
@@ -0,0 +1,11 @@
+#!/usr/bin/awk -f
+{
+ if ($1 < 1024) print int($1)" B"
+ else if ($1 < 1024^2) print int($1 / 1024)" KiB"
+ else if ($1 < 1024^3) print int($1 / 1024^2)" KiB"
+ else if ($1 < 1024^4) print int($1 / 1024^3)" MiB"
+ else if ($1 < 1024^5) print int($1 / 1024^4)" GiB"
+ else if ($1 < 1024^6) print int($1 / 1024^4)" TiB"
+ else if ($1 < 1024^7) print int($1 / 1024^4)" PiB"
+ else print int($1 / 1024^7)" EiB"
+}