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.
- Size: 6 –> Confirms total actual size of file content is 6 bytes
- Blocks: 8 –> Total 512 byte blocks. Hence there are eight 512 bytes blocks, so file size should be 8*512bytes=4K.
[root@nglinux ~]# du -sh file1 4.0K file1
- IO Block: 4096 –> Confirms the IO block size of 4096 bytes i.e. 4K.
- regular file –> Shows if it is a regular file, directory, block file or a character file.
- Device: 801h/2049d –> On which device the file is located.
### Here 801 is the device number in hex notation. ### And 2049 is the device number in decimal format.
### 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
### 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 ~]#
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.
I hope you like the article.
Do post your comments/suggestions below.