-2

When I run stat for a file test I got the following output.

> [ec2-user@ip-172-31-55-186 ~]$ stat test   
> File: ‘test’   Size: 538   
> Blocks: 8          IO Block: 4096   regular file Device: ca01h/51713d 
> Inode: 524329      Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 
> 500/ec2-user)   Gid: (  500/ec2-user) Access: 2015-05-04
> 17:28:43.644190329 +0000 Modify: 2015-05-04 17:28:43.644190329 +0000
> Change: 2015-05-04 17:28:43.648190373 +0000  Birth: -

My question is, if the file size is 538 bytes, why the file has to use 8 blocks? One IO block size is 4096 bytes, isn't 1 block is enough?

Balasekhar Nelli
  • 1,177
  • 4
  • 18
  • 30

1 Answers1

1

If you look at the manpage for stat:

The st_blocks field indicates the number of blocks allocated to the file, 512-byte units. (This may be smaller than st_size/512 when the file has holes.)

So the stat output 'Blocks' refers to st_blocks which are 512 bytes.

If you run 'du' on the file you will notice that it is indeed 4096 bytes.

$ du -h test
4.0K    test
JakeGreen
  • 89
  • 5