linux stat命令

linux stat命令主要用于显示文件或文件系统的详细信息:

stat test.sh 

  File: ‘test.sh’
  Size: 38        	Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 1269768     Links: 1
Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-07-30 15:13:20.692716580 +0800
Modify: 2022-07-30 15:12:49.869716580 +0800
Change: 2022-07-30 15:12:49.869716580 +0800
 Birth: -
155F7DE9-0DF3-E24F-B268-C06DA6DD2F44:/tmp/luolin # stat -f test.sh 
  File: "test.sh"
    ID: 9574a1b9f6400775 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 5127839    Free: 3897457    Available: 3635313
Inodes: Total: 1310720    Free: 1183243

内容:

文件的字节数
文件拥有者的 User ID
文件的 Group ID
文件的读、写、执行权限
文件的时间戳,共有三个:
ctime 指 inode 上一次变动的时间
mtime 指文件内容上一次变动的时间
atime 指文件上一次打开的时间。
链接数,即有多少文件名指向这个
inode 文件数据 block 的位置

Linux下的三个时间:

  1. Access Time:简写为atime,表示文件的访问时间。当文件内容被访问时,更新这个时间 ls -l
  2. Modify Time:简写为mtime,表示文件内容的修改时间,当文件的数据内容被修改时,更新这个时间 ls -lc
  3. Change Time:简写为ctime,表示文件的状态时间,当文件的状态被修改时,更新这个时间,例如文件的链接数,大小,权限,Blocks数ls -lu

什么是 inode?
参考链接

参数说明:

-f  不显示文件本身的信息,显示文件所在文件系统的信息

stat -f test.sh 
  File: "test.sh"
    ID: 9574a1b9f6400775 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 5127839    Free: 3897659    Available: 3635515
Inodes: Total: 1310720    Free: 1183324

-t  简洁模式,只显示摘要信息

stat -t test.sh 
test.sh 38 8 81a0 0 0 fd00 1269768 1 0 0 1659165200 1659165169 1659165169 0 4096

-c 输出指定格式的文件信息

stat -c %a test.sh 
640
stat -c %A test.sh 
-rw-r-----

更多命令可以参考:

stat --help
Usage: stat [OPTION]... FILE...
Display file or file system status.

Mandatory arguments to long options are mandatory for short options too.
  -L, --dereference     follow links
  -f, --file-system     display file system status instead of file status
  -c  --format=FORMAT   use the specified FORMAT instead of the default;
                          output a newline after each use of FORMAT
      --printf=FORMAT   like --format, but interpret backslash escapes,
                          and do not output a mandatory trailing newline;
                          if you want a newline, include \n in FORMAT
  -t, --terse           print the information in terse form
      --help     display this help and exit
      --version  output version information and exit

The valid format sequences for files (without --file-system):

  %a   access rights in octal
  %A   access rights in human readable form
  %b   number of blocks allocated (see %B)
  %B   the size in bytes of each block reported by %b
  %C   SELinux security context string
  %d   device number in decimal
  %D   device number in hex
  %f   raw mode in hex
  %F   file type
  %g   group ID of owner
  %G   group name of owner
  %h   number of hard links
  %i   inode number
  %m   mount point
  %n   file name
  %N   quoted file name with dereference if symbolic link
  %o   optimal I/O transfer size hint
  %s   total size, in bytes
  %t   major device type in hex, for character/block device special files
  %T   minor device type in hex, for character/block device special files
  %u   user ID of owner
  %U   user name of owner
  %w   time of file birth, human-readable; - if unknown
  %W   time of file birth, seconds since Epoch; 0 if unknown
  %x   time of last access, human-readable
  %X   time of last access, seconds since Epoch
  %y   time of last modification, human-readable
  %Y   time of last modification, seconds since Epoch
  %z   time of last change, human-readable
  %Z   time of last change, seconds since Epoch
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值