Page MenuHomeDevCentral

Parse and sum size expressions like 1G or 200M
ClosedPublic

Authored by dereckson on Dec 25 2023, 19:54.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 18:34
Unknown Object (File)
Tue, Nov 19, 18:11
Unknown Object (File)
Tue, Nov 19, 14:17
Unknown Object (File)
Tue, Nov 19, 12:39
Unknown Object (File)
Tue, Nov 19, 06:43
Unknown Object (File)
Mon, Nov 18, 20:26
Unknown Object (File)
Mon, Nov 18, 20:12
Unknown Object (File)
Mon, Nov 18, 16:46
Subscribers
None

Details

Summary

ZFS commands like zfs list -t snapshot display sizes easy to read
by humans like 0B, 5K, 1G, 200M or 3T.

To answer questions like "What's the total size of all the snapshots
for that dataset?", this means to be able to compute basic additions
using terms with units.

This utility can do this:

zfs list -t snapshot | grep name | awk '{print $2}' | space-sum

Test Plan
  • cargo build
  • space-sum -h
  • zfs list ... > zfs-sizes.txt ; space-sum zfs-sizes.txt
  • zfs list ... | space-sum

Diff Detail

Repository
rSPACESUM space-sum
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dereckson created this revision.
WindRiver
$ zfs list -t snapshot | grep dereckson | awk '{print $2}' | space-sum
2.244G

$ space-sum -h
Read size expressions like 200M or 2G and compute the sum.

Usage: space-sum [FILENAME]

Arguments:
  [FILENAME]  The file containing sizes to sum. If omitted, values are read from stdin.

Options:
  -h, --help     Print help
  -V, --version  Print version
This revision is now accepted and ready to land.Dec 25 2023, 20:07