Search This Blog

Wednesday, November 4, 2009

Small trick with a 'stat' tool in Linux

I used many times 'stat' tool to find out information about a physical file. Normally the output looks like that:

user@host:/tmp$ stat myfile.txt
File: `myfile.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 325124 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/radoslaw) Gid: ( 1000/radoslaw)
Access: 2009-11-04 16:15:07.000000000 +0100
Modify: 2009-11-04 16:15:07.000000000 +0100
Change: 2009-11-04 16:15:07.000000000 +0100

There is another very useful options, -f, that shows different information.

user@host:/tmp$ stat -f myfile.txt
File: "myfile.txt"
ID: a0fb1614334b9c81 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 2460827 Free: 647809 Available: 522804
Inodes: Total: 625856 Free: 407715

In the output you can find a lot of file system related information, like the block size or file system name.

And When you want to find only the file system name you can run:

user@host:/tmp$ stat -f -c "%T" myfile.txt
ext2/ext3

No comments:

Post a Comment