Skip to content

Instantly share code, notes, and snippets.

@dorokhin
Created May 6, 2021 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorokhin/ad0a5dd548a38792c27eb24ba03ad179 to your computer and use it in GitHub Desktop.
Save dorokhin/ad0a5dd548a38792c27eb24ba03ad179 to your computer and use it in GitHub Desktop.
Disk space to json

Implementation used jq

df -Ph | \
  jq -R -s '
    [
      split("\n") |
      .[] |
      if test("^/") then
        gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
      else
        empty
      end
    ]'
    
# output:

[
  {
    "mount": "/dev/mapper/vgubuntu-root",
    "spacetotal": "468G",
    "spaceavail": "52G"
  },
  {
    "mount": "/dev/loop1",
    "spacetotal": "56M",
    "spaceavail": "56M"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment