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
F3603129: D3254.diff
Sun, Sep 29, 06:04
Unknown Object (File)
Tue, Sep 17, 08:59
Unknown Object (File)
Thu, Sep 12, 00:49
Unknown Object (File)
Thu, Sep 12, 00:49
Unknown Object (File)
Thu, Sep 12, 00:45
Unknown Object (File)
Thu, Sep 12, 00:42
Unknown Object (File)
Mon, Sep 2, 15:18
Unknown Object (File)
Aug 28 2024, 07:55
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