My stat /etc command shows that the number of blocks is 24. I understand that a block here means 512 bytes. So the total size is 24 × 512 which makes it 12288 bytes.

But it shows 8192 bytes instead, and I can't understand why. To my mind it should be 12288 (3 × 4096).

$ stat /etc
  File: /etc
  Size: 8192            Blocks: 24         IO Block: 4096   directory
Device: fd00h/64768d    Inode: 16777345    Links: 152
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-28 00:03:35.470200471 +0100
Modify: 2022-01-27 23:59:09.331606660 +0100
Change: 2022-01-27 23:59:09.331606660 +0100
 Birth: -

/etc is on an XFS file system.


1 Answer 1


Since this is on XFS, the discrepancy between the reported size of /etc and the number of blocks allocated to it is probably caused either by preallocation, or by directory shrinking. If you look at your file system with xfs_db (xfs_db -r /dev/...), you can look at the allocated blocks; for example,

$ sudo xfs_db -r ...
xfs_db> inode 16777345
xfs_db> print
u3.bmx[0-3] = [startoff,startblock,blockcount,extentflag] 

(The inode command above is correct for your system, but your output will differ.)

This is from a directory with a size of 12,288 bytes but an allocated size of 16,384 bytes (32 blocks reported by stat). This shows up as three data blocks (start offsets 0, 1, 2), and an extra block (start offset 8388608) which is part of the “freelist”, i.e. a block allocated to the directory but not used by the directory’s data.

  • I see a similar discrepancy for a few directories on an ext4 filesystem. For ext4, if there are 12 or more blocks then there's an indirect block (or more but that would be huge for a directory). But I also see an extra block for a few directories that are smaller: e.g. /etc/alternatives (it's an Ubuntu system) has 80 half-kB blocks but size 36864. Does this indicate that it used to have ≥12 data blocks, then it shrunk but there's still an indirect block? Commented Jan 28, 2022 at 11:02
  • @Gilles that’s interesting, I see the same on a Debian system (/etc/alternatives with 96 allocated blocks but a size of 45,056). AFAIK Ext4 doesn’t shrink its directories online, only with e2fsck -D); I don’t know what the extra block is there... Commented Jan 28, 2022 at 11:06
  • BTW the wiki is no longer the reference for Ext4 file system layout documentation; see kernel.org/doc/html/latest/filesystems/ext4/… instead. Commented Jan 28, 2022 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .