Linux stat Command

by mike on May 9, 2011

stat
The stat utility allows you to see all information about either a file or a directory.  You can use wildcards if you want to see info for more than one object at a time.

stat process.sh
File: `process.sh'
Size: 158           Blocks: 16         IO Block: 4096   regular file
Device: 305h/773d    Inode: 98134       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2010-08-18 11:16:37.000000000 -0600
Modify: 2010-08-16 09:44:57.000000000 -0600
Change: 2010-08-16 09:44:57.000000000 -0600

Here is a second example which may help clarify the issues with blocks and size of file.

stat resource.sh
File: `resource.sh'
Size: 1114            Blocks: 8          IO Block: 4096   regular file
Device: 824h/2084d      Inode: 12456570    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/    mike)   Gid: ( 1000/    mike)
Access: 2011-05-09 08:25:11.049624485 -0600
Modify: 2011-04-10 07:04:35.495650374 -0600
Change: 2011-04-10 07:07:46.631150468 -0600

Most of this should be self-explanatory, but a few items bear explaining.

* Blocks–Each file occupies a certain number of filesystem blocks on the harddrive.
* IO Block–This is the size of the IO block.
* Device–The number of your storage device (harddrive, etc.)
* Inode–The inode number that the file or directory is linked to.
* Times–Note that the timestamps also include which time zone that accesses or modifications took place in.  The “-0500″ signifies the Eastern Standard  time zone.

You can use the “-c” switch, along with the appropriate option, if you only want to look at one particular piece of information.  For example, if you only want to look at the file’s permissions setting, you can enter:

stat -c%A process.sh
-rw-r--r--

If you want to see information on a particular directory, use the “-f” switch.

stat -f /etc
File: "/etc"
ID: 0        Namelen: 255     Type: reiserfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 1977922    Free: 1272318    Available: 1272318
Inodes: Total: 0          Free: 0

Here, you see the size of the filesystem blocks in bytes, and how many blocks are free.  Don’t worry about having zero inodes, since this drive is formatted with reiserfs filesystem.  That’s just how reiserfs reports things.  In reality, there are plenty of inodes left for use.  For comparison, here’s how it would look on an ext3 filesystem.

stat -f /etc
File: "/etc"
ID: 0        Namelen: 255     Type: ext2/ext3
Blocks: Total: 9466244    Free: 7530719    Available: 7049849    Size: 4096
Inodes: Total: 4816896    Free: 4586664

With ext2 or ext3, you can see both the total and the available number of inodes.  Since Linux uses an inode for each file, it appears that we can place 4,586,664 more files on this harddrive.

{ 3 comments }

Jim Bauwens May 10, 2011 at 7:04 am

Thank you for this howto! I’ve been a long Linux user, but did know that stat existed.

Thank you very much!

Jeff Sadowski May 10, 2011 at 8:28 pm

Some numbers don’t add up.
In your explanation of blocks you say it takes eight blocks but stat lists Blocks:16
Is there something I’m missing or is that just a typo?
Also if each block is 4096 is that bits or bites?
If each block is 4096 and there are 16 is that 65536 units on the disk?
it seems that is far overkill for a file that is 158 and again is this bits or bites? Is this for alignment purposes?

Scott Atkinson May 11, 2011 at 10:25 am

Folks -

Am I missing something or is it a typo? You write that the file occupies 8 blocks, but your readout has the number 16.

Thanks,

Scott A.
Watertown NY

Comments on this entry are closed.

Previous post:

Next post: