linux里stat的作用,linux:stat

本文介绍了stat命令的详细用法,包括选项-L、-f、-t等,展示了如何获取文件的访问、修改和创建时间,以及stat函数的原型和参数。通过实例说明了如何使用stat来查看文件状态信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

#include

#include

参数

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*/

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值