1
$ stat -c %s,%o,%b foo.txt
631,4096,8
$ stat -c %s,%o,%b bar.txt
5952,4096,16

Why the number of blocks is always a multiple of 8? I thought the number of blocks of a file is the smallest integer that satisfies filesize <= blocksize * blockcount.

3
  • What's the output of dumpe2fs /dev/sda1 | grep Block (/dev/hda1 for an IDE disk)?
    – user1931
    Jun 14, 2010 at 4:18
  • Block count: 2441880 / Block size: 4096 / Blocks per group: 32768 / Group 0: ... / Jun 14, 2010 at 4:22
  • Since you're using a block size of 4K, the min will always be 8. 4096/512=8. Edit: See Ignacio's answer.
    – user1931
    Jun 14, 2010 at 4:42

1 Answer 1

4

%b returns the number of blocks on the filesystem that are allocated for the file, where each block is 512 bytes. Since the smallest block on the filesystem is 4kB, the number of blocks returned by stat will always be a multiple of 8 (4096 ÷ 512 = 8).

5
  • Thank you for your answer! But I still don't understand. 512 bytes? Where does it come from? Jun 14, 2010 at 4:54
  • 2
    I don't know the entire history, but the sector size of disks used to be 512 bytes. Jun 14, 2010 at 5:35
  • 512-bytes blocks dates from the early days of Unix, and stayed in Linux for historical reasons. Thay have no relation to today's hard disks.
    – harrymc
    Jun 14, 2010 at 10:03
  • @harry, Ignacio: they are not relating to Unix, but are to harddisks. And while hard disks don't really store information in 512-byte blocks, all of them are using LBA for addressing, which is 512-byte-discrete.
    – Catherine
    Jun 14, 2010 at 13:49
  • Everything is a multiple of 8 because computer systems generally describe data in bits (base2 or 0 or 1 per digit) and bytes (base8 or 0-8 per digit) and hex (base 16 or 0-16 per digit) whereas 'normal' math is almost always base 10 (0-10 per digit). BTW, +1 for nice explanation. Jun 15, 2010 at 8:52

You must log in to answer this question.

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