Site icon New Generation Enterprise Linux

See file or filesystem status in Linux: stat command usage.

In this post we will look how to check the file or filesystem status in Linux.

i.e. the powerful and most useful stat command usage in linux.

Lets see how to use stat command and what all information it shows.

Viewing File status: stat command usage & description

[root@nglinux ~]# stat file1
  File: `file1'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d	Inode: 917831      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-01-10 23:09:52.620055969 -0800
Modify: 2018-01-10 23:00:04.925057120 -0800
Change: 2018-01-10 23:11:48.397055846 -0800
[root@nglinux ~]#

In the above command, we ran stat on a random file “file1” and we can see all information of the inode.

We can brief the information in points below.

### Here 801 is the device number in hex notation.
### And 2049 is the device number in decimal format.
  • Links: 1 –> “1” for a file(either regular, character or block) and 2 for directory inode.
    ### 2 for directory inode(since 1 for itself, and one for ".." or "." resides inside the directory.)
    [root@nglinux ~]# stat dir1
      File: `dir1'
      Size: 4096      	Blocks: 8          IO Block: 4096   directory
    Device: 801h/2049d	Inode: 929020      Links: 2
    
  • Access: (0644/-rw-r–r–) –> Shows permissions of the file/dir.
  • Uid: ( 0/ root) Gid: ( 0/ root) –> Contains UID and GID of the file which we see in ls -l output.
    ### Here we have root as uid and gid.
    [root@nglinux ~]# ls -l file1
    -rw-r--r--. 1 root root 6 Jan 10 23:00 file1
    [root@nglinux ~]# 
    
  • Access: 2018-01-13 01:21:57.347903176 -0800 –> Shows last access time of the file(i.e when the file was read last time).
  • Modify: 2018-01-10 23:00:04.925057120 -0800 –> Shows last modification time of the file’s contents.
  • Change: 2018-01-10 23:11:48.397055846 -0800 –> Shows last metadata change time of the file(for example last time when permission change/ACL change or file attributes were changes)
  • Viewing File system information with stat
    We can also view filesystem inode and space information with stat command using -f option.

    [root@nglinux ~]# stat -f /dev/sda1
      File: "/dev/sda1"
        ID: 0        Namelen: 255     Type: tmpfs
    Block size: 4096       Fundamental block size: 4096
    Blocks: Total: 125679     Free: 125625     Available: 125625
    Inodes: Total: 125679     Free: 125008
    [root@nglinux ~]# 
    

    Here we can see all information of nodes, blocks, and its id.

    The stat command reads information from the respective file’s inode, and displays most of the inode information.

    I hope you like the article.

    Do post your comments/suggestions below.

    0 0 votes
    Article Rating
    Exit mobile version