Hack 26. Stat Command Examples

by Ramesh

Stat command can be used either to check the status/properties of a single file or the filesystem.

Display statistics of a file or directory.

  1. $ stat /etc/my.cnf
  2.  
  3. File: `/etc/my.cnf'
  4. Size: 346 Blocks: 16 IO Block: 4096 regular file
  5. Device: 801h/2049d Inode: 279856 Links: 1
  6. Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
  7. Access: 2009-01-01 02:58:30.000000000 -0800
  8. Modify: 2006-06-01 20:42:27.000000000 -0700
  9. Change: 2007-02-02 14:17:27.000000000 -0800
  10.  
  11. $ stat /home/ramesh
  12.  
  13. File: `/home/ramesh'
  14. Size: 4096 Blocks: 8 IO Block: 4096 directory
  15. Device: 803h/2051d Inode: 5521409 Links: 7
  16. Access: (0755/drwxr-xr-x) Uid: ( 401/ramesh) Gid: ( 401/ramesh)
  17. Access: 2009-01-01 12:17:42.000000000 -0800
  18. Modify: 2009-01-01 12:07:33.000000000 -0800
  19. Change: 2009-01-09 12:07:33.000000000 -0800

Display the status of the filesystem using option –f

  1. $ stat -f /
  2.  
  3. File: "/"
  4. ID: 0 Namelen: 255 Type: ext2/ext3
  5. Blocks: Total: 2579457 Free: 2008027 Available: 1876998 Size: 4096
  6. Inodes: Total: 1310720 Free: 1215892