JSON Output
Outcome: the whole mount inventory as data your scripts can trust — with the field names right, the totals checked against df in bytes, and a clear warning about which list the JSON actually is. This is the chapter where duf stops being a prettier df and becomes a different kind of tool.
The shape of the data
./duf --json
One JSON array, one object per mounted filesystem:
{
"device": "overlay",
"device_type": "local",
"mount_point": "/",
"fs_type": "overlay",
"type": "",
"opts": "rw,relatime",
"total": 8053063680,
"free": 5290307584,
"used": 2625245184,
"inodes": 0,
"inodes_free": 0,
"inodes_used": 0,
"blocks": 1966080,
"block_size": 4096
}
Everything is a count of bytes or
blocks — no friendly units, nothing
rounded. Note the field names
carefully, because the obvious
guesses are wrong: the size field is
total, not size, and the
available field is free, not
avail — the table's column names
are not the JSON's field names. The
lab learned this the way readers
would: its first checker crashed on
a missing size key, and its first
jq query answered null — jq does
not complain about a field that is
not there, it just prints nothing's
name. Transcript t10 keeps both
failures; the fix is one word each.
device_type carries the group of
chapter 2 — local, network,
special — so scripts can filter by
group even though the tables are
gone.
Working queries
Counting a filesystem type across the whole machine:
./duf --json | jq '[.[] | select(.fs_type=="tmpfs")] | length'
39
Reading one mount's raw figures (/tmp appears twice — the machine mounts it twice, and the JSON says so, twice):
./duf --json | jq -r '.[] | select(.mount_point=="/tmp") | "\(.mount_point) \(.total) bytes, \(.used) used"'
/tmp 536870912 bytes, 430080 used
/tmp 536870912 bytes, 430080 used
The byte-for-byte check
The lab's checker
(duf-lab/check-json.py) sums the
array, then holds the root
filesystem's figures against df's
own byte counts (df --output
-B1 /):
duf reports 76 mounted filesystems in its JSON
duf, mount / : total=8053063680 used=2625245184 free=5290307584
df, mount / : size=8053063680 used=2625245184 avail=5290307584
total agrees exactly: True
Identical, to the byte. The tables
of chapter 5 differ because of
rounding and formulas; the data
underneath does not differ at all.
The same script prints the sum of
every total in the array —
2,881.4 GB on a machine with about
200 GB of real storage — as a
standing warning: bind mounts and
stacked mounts repeat the same
storage, so never sum a mount
list and call it a machine's
capacity. The JSON is an
inventory, not a total.
The list is the unedited one
The JSON always describes all
the mounts the kernel lists — 76 on
the lab machine — regardless of the
display filters. The tidy filter of
chapter 2 does not apply, --all
makes no difference, and the lab
verified that --only local left
the JSON at 76 entries: filtering
is a table feature, and scripts are
expected to do their own with
select(...). This is the right
design for data and a genuine trap
for the unwary: a script and a
person can run "duf" on the same
machine and count different
machines' worth of filesystems,
both correctly.