Skip to content

Sorting and Choosing Columns

Outcome: the table arrives in the order that answers your question — fullest first, biggest first — and with exactly the columns that question needs. Duf's renderer (chapter 2) is steerable in two ways: --sort for order and --output for shape.

Sorting

./duf --only local --sort usage

The sort keys are the fields themselves:

mountpoint, size, used, avail, usage,
inodes, inodes_used, inodes_avail,
inodes_usage, type, filesystem

The default is mountpoint — alphabetical, the right order for looking something up. The working orders are the others: --sort size when you are asking what are my big filesystems, --sort usage for what is full, --sort avail for where is the room. An unknown key is refused politely, with the valid list printed (transcript t10):

unknown column: bogus (valid: mountpoint, size, used, avail, usage, ...)

Now the catch, stated plainly because the lab looked for the flag and it is not there: duf 0.9.1 sorts ascending only — there is no reverse option. Smallest and emptiest come first; the biggest and fullest sink to the bottom of their table. For a full screen that is a scroll away from what you wanted. The working habit is to sort and take the tail:

./duf --only local --sort usage | tail -8

Chapter 11 builds the worst-first report this way, and chapter 9 shows the script-shaped alternative, where order is yours to choose.

Choosing columns

--output takes the same field names and builds a table with only those columns, in the order you give them:

./duf --output mountpoint,size,usage --only-mp /home/hatch
│ MOUNTED ON  │   SIZE │            USE%            │
│ /home/hatch │ 200.0G │ ███▌                 18.0% │

Fewer columns buy back the thing the renderer drops first: with room to spare, the usage bar returns. The inode fields can be mixed into the block table too, without switching to the full inode view:

./duf --output mountpoint,size,used,avail,usage,inodes,inodes_used --all --only-mp /tmp
│ /tmp │ 512.0M │ 420.0K │ 511.6M │ 0.1% │ 1015613 │ 80 │

(Those last two columns are the inode story arriving early; the next chapter but one is devoted to it.) One caution: --output is a display choice, not a data choice. The JSON output of chapter 9 always carries every field whatever --output says.