Linux命令(98)之stat

linux命令之rmdir

1.stat介绍

linux命令stat用于显示文件(linux中一切皆文件)的状态信息

2.stat用法

stat [参数] file

stat常用参数
参数 说明
-f 查看文件所在文件系统状态信息
-c 按照在指定格式输出文件状态信息(指定格式如下)

-c文件有效格式符说明

格式符 说明
%a 八进制中的访问权限(644显示)
%A 人类可读形式的访问权(rwx显示)
%g 所有者的组ID
%G 所有者的组名称
%n 文件名
%u 所有者的用户ID
%U 所有者的用户名

3.实例

3.1.查看命令stat帮助

命令:

man stat

OR

stat --h

stat --help

[root@centos79-3 ~]# 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

Valid format sequences for file systems:

  %a   free blocks available to non-superuser
  %b   total data blocks in file system
  %c   total file nodes in file system
  %d   free file nodes in file system
  %f   free blocks in file system
  %i   file system ID in hex
  %l   maximum length of filenames
  %n   file name
  %s   block size (for faster transfers)
  %S   fundamental block size (for block counts)
  %t   file system type in hex
  %T   file system type in human readable form

NOTE: your shell may have its own version of stat, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

GNU coreutils online help: 
For complete documentation, run: info coreutils 'stat invocation'
[root@centos79-3 ~]# 

3.2.查看文件状态信息

命令:

stat a.txt

[root@centos79-3 ~]# stat a.txt 
  File: ‘a.txt’
  Size: 27        	Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 101365672   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-09-23 16:19:28.873029340 +0800
Modify: 2023-09-18 15:51:53.460207797 +0800
Change: 2023-09-18 15:51:53.460207797 +0800
 Birth: -
[root@centos79-3 ~]# 
文件状态信息 说明
File 显示文件名
Size 显示文件大小
Blocks 文件使用的数据块总数
IO Block IO块大小
regular file 文件类型(常规文件)
Device 设备编号
Inode Inode号
Links 链接数
Access 文件的权限
Gid、Uid 文件所有权的Gid和Uid
access time 最后存取时间(ls -lu filename),表示最后一次访问(仅仅是访问,没有改动)文件的时间
modify time 最后修改时间(ls -l  filename ),表示最后一次修改文件的时间
change time 最后更改时间(ls -lc filename ),表示最后一次对文件属性改变的时间,包括权限,大小,属性等等
Birth time 文件创建时间,crtime,不过据查此属性linux已废弃,目前状态显示结果均为-

3.3.查看文件的权限

命令:

stat -c %a

stat -c %A

[root@centos79-3 ~]# stat -c %a a.txt
644
[root@centos79-3 ~]# stat -c %A a.txt
-rw-r--r--
[root@centos79-3 ~]# 

3.4.查看文件所有者的用户ID

命令:

stat -c %u a.txt

[root@centos79-3 ~]# stat -c %u a.txt
0

3.5.查看文件所有者的用户名

命令:

stat -c %U a.txt

[root@centos79-3 ~]# stat -c %U a.txt
root
[root@centos79-3 ~]# 

3.6.查看文件所有者的组ID

命令:

stat -c %g a.txt

[root@centos79-3 ~]# stat -c %g a.txt
0

3.7.查看文件所有者的组名

命令:

stat -c %G a.txt

[root@centos79-3 ~]# stat -c %G a.txt
root
[root@centos79-3 ~]# 

3.8.查看文件的文件名称

命令:

stat -c %n a.txt

[root@centos79-3 ~]# stat -c %n a.txt
a.txt
[root@centos79-3 ~]# 

3.9.查看命令stat的版本信息

命令:

stat --version

[root@centos79-3 ~]# stat --version
stat (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Meskes.
[root@centos79-3 ~]# 

你可能感兴趣的:(Linux命令,linux,运维,服务器,stat)