Linux stat command used to display files and file system information like permission, size etc. In this tutorial we will look various usage examples.
Linux stat命令用于显示文件和文件系统信息,例如权限,大小等。在本教程中,我们将查看各种用法示例。
显示文件信息 (Show File Information)
All information about a file can be get without providing any parameter. We will only provide the file name.
无需提供任何参数即可获取有关文件的所有信息。 我们将仅提供文件名。
$ stat a.txt
As we can see from screenshot there is information about file name , size, blocks, inode, device, access,modify,change dates, user and group id and access rights.
从屏幕截图中可以看到,其中包含有关文件名,大小,块,inode,设备,访问,修改,更改日期,用户和组ID以及访问权限的信息。
显示文件系统信息 (Show File System Information)
We can get information about the file system too. But we need some rights to read these file system attributes. This right can be provided with sudo
command or root
user.
我们也可以获得有关文件系统的信息。 但是我们需要一些权限才能读取这些文件系统属性。 可以使用sudo
命令或root
用户提供此权限。
$ stat /dev/vda1
As we can see from screenshot there is information about file name , size, blocks, inode, device, access,modify,change dates, user and group id and access rights.
从屏幕截图中可以看到,其中包含有关文件名,大小,块,inode,设备,访问,修改,更改日期,用户和组ID以及访问权限的信息。
显示文件权限 (Show File Permissions)
File permissions about a file can be get like below. First command will output humen readable format, second will print octal format.
关于文件的文件权限可以如下获得。 第一个命令将输出人类可读格式,第二个将打印八进制格式。
$ stat --format %A a.txt
OR
要么
$ stat --format %a a.txt
显示SELinux安全上下文 (Show SELinux Security Context)
SELinux is security implementation about Linux operating systems. Files are restricted according to this security context. This context information can be get like below.
SELinux是有关Linux操作系统的安全性实现。 根据此安全上下文限制文件。 该上下文信息可以如下获取。
$ stat --format %C a.txt
显示文件类型 (Show File Type)
File type like regular, block, link etc. can be printed with the following command. First command will show in human readable format. Second command will show octal format.
可以使用以下命令打印常规,块,链接等文件类型。 第一个命令将以人类可读的格式显示。 第二个命令将显示八进制格式。
$ stat --format %F a.txt
OR
要么
$ stat --format %f a.txt
显示用户(Show User)
Every file in Linux have a owner user. This user information can be get with stat command. First command will show human readable format, second command will show in decimal number of the user id.
Linux中的每个文件都有一个所有者用户。 可以使用stat命令获取此用户信息。 第一个命令将显示人类可读的格式,第二个命令将以用户ID的十进制数字显示。
$ stat --format %U a.txt
OR
要么
$ stat --format %u a.txt
显示组(Show Group)
Every file in Linux have a owner group. This group information can be get with stat command. First command will show human readable format, second command will show in decimal number of the group id.
Linux中的每个文件都有一个所有者组。 该组信息可以通过stat命令获得。 第一个命令将显示人类可读的格式,第二个命令将以组ID的十进制数字显示。
$ stat --format %G a.txt
OR
要么
$ stat --format %g a.txt
显示索引节点编号(Show Inode Number)
Inode numbers are used to specify files in file systems. this inode number can be printed with stat command like below.
索引节点号用于指定文件系统中的文件。 可以使用stat命令打印此索引节点号,如下所示。
$ stat --format %i a.txt
显示硬链接数(Show Number Of Hard Links)
Linux provides ability to link existing files. Those are two type soft link and hard link. The hard link count can be printed like below.
Linux提供了链接现有文件的功能。 这是两种类型的软链接和硬链接。 硬链接计数可以如下打印。
$ stat –format %h a.txt
$ stat –格式%h a.txt
显示总大小(Show Total Size)
The total size of the provided file can be printed like below with stat command.
可以使用stat命令如下打印所提供文件的总大小。
$ stat --format %s a.txt
显示最后修改 (Show Last Modification)
Las modification time can be printed like below. First will print in a human readable format and second command will print epoch time.
可以按如下方式打印修改时间。 第一个将以人类可读的格式打印,第二个命令将打印纪元时间。
$ stat --format %y a.txt
OR
要么
$ stat --format %Y a.txt
显示最后更改(Show Last Change)
Last change time can be printed like below. First will print in a human readable format and second command will print epoch time.
上次更改时间可以如下打印。 第一个将以人类可读的格式打印,第二个命令将打印纪元时间。
$ stat --format %z a.txt
OR
要么
$ stat --format %Z a.txt
显示最后访问(Show Last Access)
Last access time can be printed like below. First will print in a human readable format and second command will print epoch time.
上次访问时间可以如下打印。 第一个将以人类可读的格式打印,第二个命令将打印纪元时间。
$ stat --format %x a.txt
OR
要么
$ stat --format %X a.txt
翻译自: https://www.poftut.com/linux-stat-command-tutorial-examples/