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)
Fri, Dec 6, 10:28
Unknown Object (File)
Wed, Nov 27, 21:46
Unknown Object (File)
Tue, Nov 26, 18:11
Unknown Object (File)
Tue, Nov 26, 17:52
Unknown Object (File)
Nov 22 2024, 22:47
Unknown Object (File)
Nov 19 2024, 18:34
Unknown Object (File)
Nov 19 2024, 18:11
Unknown Object (File)
Nov 19 2024, 14:17
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