brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: stat -f shows block size and free inodes of the disk under a path

Disk
~/tips/tip-disk-stat-f-filesystem-info

stat -f /srv

Prints filesystem details like type, block size and free inodes for any folder.

Most people know stat for file details. With -f it describes the filesystem that holds the path instead, and that answers a few questions df doesn’t.

stat -f /srv

You get the filesystem type, the block size, the total and free blocks, and the total and free inodes. In a container, stat -f /tmp shows type overlayfs, a block size of 4096 and the inode counts.

The block size explains why a 10 byte file takes 4K of space: every file uses at least one block. Millions of tiny files on a filesystem with large blocks waste a lot. The free inode count tells you whether you can still create files at all, the same as df -i but for one path.

With -c you pick just the values you want, which I find easy to use in a script:

stat -f -c '%T block=%S free_inodes=%d' /srv

%T is the type in readable form, %S the fundamental block size and %d the free inodes. The man page lists the others.

Some filesystems report numbers that aren’t very meaningful. Btrfs and ZFS create inodes as needed, so their inode totals can look odd or change. And on macOS, stat -f means something else entirely: it’s the format option there, so this only works with GNU stat.

Further reading: stat(1) manual page

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link