stat
命令
用于显示文件的状态信息。stat命令的输出信息比ls命令的输出信息要更详细。
语法格式:
stat(选项)(参数)
其中,可用的选项为
-L:支持符号连接;
-f:显示文件系统状态而非文件状态;
-t:以简洁方式输出信息;
--help:显示指令的帮助信息;
--version:显示指令的版本信息。
参数为:
文件:指定要显示信息的普通文件或者文件系统对应的设备文件名。
~$ stat hello
File: hello
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 10766181 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ fck) Gid: ( 1000/ fck)
Context: system_u:object_r:unlabeled_t:s0
Access: 2020-05-17 15:19:00.711088118 +0800
Modify: 2020-05-17 15:19:00.711088118 +0800
Change: 2020-05-17 15:19:00.711088118 +0800
Birth: -
Access:最近访问时间
Modify:最近修改时间 指文件内容的修改时间
Change:最近改动时间 最近改inode的时间
stat
函数
作用 | 查询一个文件的信息 |
---|---|
函数原型 |
int stat(const char* path, struct stat *buf) int fstat(int fd, struct stat *buf) int lstat(const char* path, struct stat *buf)
|
头文件 |
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
|
参数 |
path :文件的路径buf :要返回的文件信息fd :要查询的文件的文件描述符 |
返回值 | 成功:0 失败: -1
|
struct stat{
dev_t st_dev; /*ID of device containing file*/
ino_t st_ino; /*inode number*/
mode_t st_mode; /*protection*/
nlink_t st_nlink; /*number of hard links*/
uid_t st_uid; /*user ID of owner*/
gid_t st_gid; /*group ID of owner*/
dev_t st_rdev; /*device ID (if special file)*/
off_t st_size; /*total size, in bytes*/
blksize_t st_blksize; /*blocksize for file system I/O*/
blkcnt_t st_blocks; /*number of 512B blocks allocated*/
time_t st_atime; /*time of last access*/
time_t st_mtime; /*time of last modification*/
time_t st_ctime; /*time of last status change*/
}
网友评论