linux 编程之stat 获取文件信息

本文介绍了如何在Linux环境下使用C语言的stat函数来获取文件的详细信息,包括文件大小和修改时间。通过提供文件名作为参数,程序能够调用getFileStat()函数来展示相应的文件属性。
摘要由CSDN通过智能技术生成

Linux 下有如下API 可以用来获取文件相关信息,譬如文件大小,修改时间等;

       #include <sys/types.h>
       #include <sys/stat.h>
       #include <unistd.h>

       int stat(const char *pathname, struct stat *buf);
       int fstat(int fd, struct stat *buf);
       int lstat(const char *pathname, struct stat *buf);

//struct stat 结构体
            struct stat {
             dev_t     st_dev;         /* ID of device containing file */ 文件ID
             ino_t     st_ino;         /* inode number */  文件节点
             mode_t    st_mode;        /* protection */  文件的模式
             nink_t   st_nlink;       /* number of hard links */  文件的硬链接数
             uid_t     st_uid;         /* user ID of owner */   文件所有者ID
             gid_t     st_gid;         /* group ID of owner */  文件的组ID
             dev_t     st_rdev;        /* device ID (if special file) */ 文件的设备ID
             off_t     st_size;        /* total size, in bytes */
             blksize_t st_blksize;     /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值