每天学习一个命令 stat

1、什么事stat

  • stat 是查看文件的属性

  • stat指令:文件/文件系统的详细信息显示。

2、stat的常用参数

  • stat命令主要用于显示文件或文件系统的详细信息,该命令的语法格式如下:
  • -f  不显示文件本身的信息,显示文件所在文件系统的信息
  • -Z 打印SElinux安全上下文信息
  • -L  显示符号链接 跟踪链接
  • -c 自定义输出格式,结尾有换行 {这个也是最常用的啊}
  • -t  简洁模式,只显示摘要信息
  • -f 是显示文件系统 (显示文件系统状态而不是文件状态)

3、自定义选项

% A 是以八进制访问权限
[root@king ~]# stat -c %A 2.txt 
-rw-r--r--

% b 是人类可读的访问权限
[root@king ~]# stat -c %b sftp/
0
[root@king ~]# stat -c %b python/
0
[root@king ~]# stat -c %b anaconda-ks.cfg 
8
[root@king ~]# stat -c %b 文件目录判断.sh
8

%B 是读取每个块字节的大少
[root@king bin]# stat -c %B python3
512
[root@king bin]# stat -c %B pip3.7 
512

%C 是查看文件的seliunx 的安全上下文
%D 是显示十进制的设备号
%d 是显示16进制的设备号
[root@king ~]# stat -c %D 2.txt 
fd00


[root@king ~]# stat -c %D 2.txt 
fd00
[root@king ~]# stat 2.txt 
  文件:"2.txt"
  大小:25        	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:34645084    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2019-09-30 13:49:04.043690286 +0800
最近更改:2019-09-30 13:48:53.380067150 +0800
最近改动:2019-09-30 13:48:53.380067150 +0800
创建时间:-
[root@king ~]# stat -c %d 2.txt 
64768

%c 是显示原始的文件模式
[root@king ~]# stat -c %f 2.txt 
81a4

%F 是显示 文件类型
[root@king ~]# stat -c %F 2.txt 
普通文件
[root@king ~]# stat -c %F http/
目录

% G 查看所属者的名称
%g 查看所属者的ID
[root@king ~]# stat -c %G 2.txt 
root
[root@king ~]# stat -c %G 1.txt 
king


[root@king ~]# stat -c %g 2.txt 
0
[root@king ~]# stat -c %g 1.txt 
1002
[root@king ~]# cat /etc/passwd | grep  king
king:x:1001:1002::/home/king:/bin/bash
[root@king ~]# cat /etc/passwd | grep  root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
roo:x:1000:1001:root:/home/roo:/bin/bash
sftpboss:x:1002:1003::/root/sftp/:/sbin/nologin

%U所有者的用户ID
%u 所有者用户名
[root@king ~]# stat -c %U 1.txt 
king
[root@king ~]# stat -c %u 1.txt 
1001
[root@king ~]# stat -c %u 2.txt 
0
[root@king ~]# stat -c %U 2.txt 
root

% h 是查看文件的硬链接数 (注意这里不是指软链接)
  • 软连接的设置是 ln -s 源目标文件 目标文件 (注意这里的目标文件需要不存在)
[root@king ~]# stat -c %h 1.txt 
1

[root@king ~]# ln -s 1.txt  4.txt

[root@king ~]# stat  -c %h 1.txt 
1

%i 是显示文件的索引编号
[root@king ~]# stat -c %i 1.txt 
34536758

%o 是最佳的io 写入
[root@king ~]# stat -c %o 1.txt
4096

%n引用的文件名,带有取消引用if符号链接
[root@king ~]# stat -c %n 1.txt 
1.txt
[root@king ~]# stat -c %n http/
http/
[root@king ~]# stat -c %N  1.txt 
"1.txt"
[root@king ~]# stat -c %N  http/
"http/"

%s 显示文件总字节
[root@king ~]# stat -c %s 1.txt 
77
[root@king ~]# stat -c %s http/
248

%t以十六进制表示的主要设备类型,用于字符/块设备特殊文件
%t十六进制的次要设备类型,用于字符/块设备特殊文件
[root@king ~]# stat -c %t 1.txt 
0
[root@king ~]# stat -c %T 1.txt 
0
[root@king ~]# stat -c %T http/ 
0

%x 最后一次访问时间,可读
%X 上次访问的时间,自纪元以来的秒数
  • 经过对比发现,是只有进去过文件,哪怕没有改变,也是会改变时间的
[root@king ~]# stat -c %x 2.txt 
2019-09-30 13:49:04.043690286 +0800
[root@king ~]# stat -c %X 2.txt 
1569822544
[root@king ~]# cat 2.txt 
tangmingqi-20191001 3456
[root@king ~]# stat -c %x 2.txt 
2019-09-30 13:49:04.043690286 +0800
[root@king ~]# vim 2.txt 
[root@king ~]# stat -c %x 2.txt 
2019-09-30 16:50:11.646907754 +0800


[root@king ~]# stat -c %x 1.txt 
2019-09-30 15:56:51.701643342 +0800
[root@king ~]# cat 1.txt 
TSN_CONFIG.ACCESSTOKEN=2019102809000061920e93d43-22d8-4785-92e3-7d6a1a8348de
[root@king ~]# stat -c %x 1.txt 
2019-09-30 15:56:51.701643342 +0800
[root@king ~]# awk -v FIELDWIDTHS="21 8" '{print $2}' 1.txt
N=201910
[root@king ~]# stat -c %x 1.txt 
2019-09-30 15:56:51.701643342 +0800
[root@king ~]# vim 1.txt 
[root@king ~]# stat -c %x 1.txt 
2019-09-30 16:54:46.095384823 +0800


%Y 上次修改的Y时间,自纪元以来的秒数
%y 上次修改的Y时间,可读
  • 这个更改时间可以跟系统的世界进行对比,可以了解到文件是否被修改
  • date +%s
[root@king ~]# stat -c %y 1.txt
2019-09-30 16:54:46.095384823 +0800
[root@king ~]# stat -c %Y 1.txt
1569833686

[root@king ~]# date +%s
1569833952

%Z上次更改的时间,可读
%Z上次更改的时间,自纪元以来的秒数
[root@king ~]# stat -c %z 1.txt 
2019-09-30 16:54:46.095384823 +0800
[root@king ~]# stat -c %Z 1.txt  
1569833686
[root@king ~]# date +%s
1569834428

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维螺丝钉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值