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)
Wed, Nov 13, 10:07
Unknown Object (File)
Thu, Oct 31, 10:54
Unknown Object (File)
Sat, Oct 26, 12:17
Unknown Object (File)
Sat, Oct 26, 12:13
Unknown Object (File)
Thu, Oct 24, 09:43
Unknown Object (File)
Oct 13 2024, 22:37
Unknown Object (File)
Oct 13 2024, 22:36
Unknown Object (File)
Oct 13 2024, 22:20
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