2020-07-11 上海
stat
该命令主要用来查看文件的基本信息,比如大小、权限,文件系统所属细节等等。
man page : stat - display file or file system status
翻译: 显示文件或者文件系统的状态信息
参数选项
参数 | 说明 |
---|---|
-L | 如果文件是链接文件,则只输出最终链接文件的信息 |
-f | 输出文件对应文件系统的信息,而非文件本身,主要用来了解对应文件系统的资源使用情况 |
-t | 简化输出模式,将内容输出成一行,方便编写shell脚本 |
示例
[root@107 ~]# stat 1.html
File: ‘1.html’
Size: 12 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 13744 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-12-12 23:37:09.350992377 -0500
Modify: 2019-12-12 23:37:09.350992377 -0500
Change: 2019-12-12 23:37:09.350992377 -0500
Birth: -
[root@107 ~]# stat -f 1.html
File: "1.html"
ID: 3c704bbeff663aa7 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 10978172 Free: 3646360 Available: 3083803
Inodes: Total: 2782560 Free: 2620325
[root@107 ~]# ln -s 1.txt 2.txt
[root@107 ~]# stat 2.txt
File: ‘2.txt’ -> ‘1.txt’
Size: 5 Blocks: 0 IO Block: 4096 symbolic link
Device: 802h/2050d Inode: 4140 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-07-11 04:35:44.822628629 -0400
Modify: 2020-07-11 04:35:44.822628629 -0400
Change: 2020-07-11 04:35:44.822628629 -0400
Birth: -
[root@107 ~]# stat -L 2.txt
File: ‘2.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 237 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-01-31 22:20:54.759444452 -0500
Modify: 2020-05-14 04:50:47.519719545 -0400
Change: 2020-05-14 04:50:47.519719545 -0400
Birth: -
输出字段解释:
- File: The name of the file. Usually, it is the same as the name we passed to stat on the command line, but It can be different if we’re looking at a symbolic link.
- Size: The size of the file in bytes.
- Blocks: The number of filesystem blocks the file requires, in order to be stored on the hard drive, default 512.
- IO Block: The size of a filesystem block.
- File type: The type of object the metadata describes. The most common types are files and directories, but they can also be links, sockets, or named pipes.
- Device: The device number in hexadecimal and decimal. This is the ID of the hard drive the file is stored on.
- Inode: The inode number. That is, the ID number of this inode. Together, the inode number and the device number uniquely identify a file.
- Links: This number indicates how many hard links point to this file. Each hard link has its own inode. So another way to think about this figure is how many inodes point to this one file. Each time a hard link is created or deleted, this number will be adjusted up or down. When it reaches zero, the file itself has been deleted, and the inode is removed. If you use stat on a directory, this number represents the number of files in the directory, including the “.” entry for the current directory and the “…” entry for the parent directory.
- Access: The file permissions are shown in their octal and traditional rwx (read, write, execute formats).
- Uid: User ID and account name of the owner.
- Gid: Group ID and account name of the owner.
- Access: The access timestamp. Not as straightforward as it might seem. Modern Linux distributions use a scheme called relatime, which tries to optimize the hard drive writes required to update the access time. Simply put, the access time is updated if it is older than the modified time.
- Modify: The modification timestamp. This is the time when file’s contents were last modified. (As luck would have it, the contents of this file were last changed four years ago to the day.)
- Change: The change timestamp. This is the time the file’s attributes or contents were last changed. If you modify a file by setting new file permissions, the change timestamp will be updated (because the file attributes have changed), but the modified timestamp will not be updated (because the file contents were not changed).
- Birth: Reserved to show the original creation date of the file, but this is not implemented in Linux.