带有示例Linux stat命令教程

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
Show File Information
Show File Information
显示文件信息

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
Show File System Information
Show File System Information
显示文件系统信息

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 File Type
Show File Type
显示文件类型

显示用户(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 User
Show User
显示用户

显示组(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 Group
Show Group
显示组

显示索引节点编号(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 Inode Number
Show Inode Number
显示索引节点编号

显示硬链接数(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提供了链接现有文件的功能。 这是两种类型的软链接和硬链接。 硬链接计数可以如下打印。

LEARN MORE  Windows Chkdsk Utility Tutorial
了解更多Windows Chkdsk实用程序教程

$ stat –format %h a.txt

$ stat –格式%h a.txt

Show Number Of Hard Links
Show Number Of Hard Links
显示硬链接数

显示总大小(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 Modification
Show Last Modification
显示最后修改

显示最后更改(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 Change
Show Last Change
显示最后更改

显示最后访问(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
Show Last Access
Show Last Access
显示最后访问

翻译自: https://www.poftut.com/linux-stat-command-tutorial-examples/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值