昨日推薦:天天學一個 Linux 命令(44):uptimenode
stat 命令用於顯示文件或文件系統的狀態。centos
stat [OPTION]... FILE...
文件:指定要顯示信息的普通文件或者文件系統對應的設備文件名安全
-L #支持符號鏈接 -f #顯示文件系統狀態而非文件狀態 -t #以簡潔方式輸出信息 -c #使用指定的格式而不是默認格式 -Z #打印 SELinux 安全上下文 --help #打印幫助信息 --version #打印的版本信息
查看文件test.txt詳細信息app
[root@centos7 ~]# stat test.txt File: ‘test.txt’ Size: 140 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 33575001 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-01-16 11:34:32.000000000 -0500 Modify: 2021-01-16 11:32:55.000000000 -0500 Change: 2021-01-16 11:38:17.157156882 -0500 Birth: - [root@centos7 ~]# stat -f test.txt File: "test.txt" ID: fd0000000000 Namelen: 255 Type: xfs Block size: 4096 Fundamental block size: 4096 Blocks: Total: 4452864 Free: 3984106 Available: 3984106 Inodes: Total: 8910848 Free: 8860529 [root@centos7 ~]# stat -t test.txt test.txt 140 8 81a4 0 0 fd00 33575001 1 0 0 1610814872 1610814775 1610815097 0 4096
獲取文件權限的數字centos7
[root@centos7 ~]# stat test.txt |awk 'NR==4' |awk -F '[(0/]' '{print $3}' 644 [root@centos7 ~]# stat test.txt |awk 'NR==4' |cut -c 11-13 644 [root@centos7 ~]# stat test.txt |sed -n '4p' |cut -c 11-13 644 [root@centos7 ~]# stat -c %a test.txt 644
文件有效格式說明spa
The valid format sequences for files (without --file-system): %a #顯示8進制訪問權限 %A #可讀格式的訪問權限 %b #可分配的塊數 %B #每一個塊的字節大小 %C #SELinux安全上下文字符串 %d #設備編號(十進制) %D #設備編號(十六進制) %f #文件類型(十六進制) %F #文件類型 %g #全部者的組ID %G #全部者的組名 %h #硬連接數 %i #inode號 %m #掛載點 %n #文件名 %N #帶引號的文件名,若是有軟連接則取消引用 %o #IO塊大小 %s #總大小(以字節爲單位) %t #十六進制的主要設備類型 %T #次設備類型(十六進制) %u #全部者的用戶ID %U #全部者的用戶 %x #最後訪問時間 %X #最後訪問時間(以秒爲單位) %y #最後修改時間 %Y #最後修改時間(以秒爲單位) %z #最後更改時間 %Z #最後更改時間(以秒爲單位)
文件系統有效格式說明:3d
Valid format sequences for file systems: %a #非超級用戶可用的空閒塊 %b #文件系統中的數據塊總數 %c #文件系統中的文件節點總數 %d #文件系統中的空閒文件節點 %f #文件系統中的空閒塊 %i #十六進制文件系統ID %l #文件名的最大長度 %n #文件名 %s #最佳傳輸塊大小 %t #十六進制的形式輸入 %T #以易讀的形式輸入
[root@centos7 ~]# stat -f /dev/sda File: "/dev/sda" ID: 0 Namelen: 255 Type: tmpfs Block size: 4096 Fundamental block size: 4096 Blocks: Total: 121517 Free: 121517 Available: 121517 Inodes: Total: 121517 Free: 121132