目录
1. stat函数
int stat(const char *path, struct stat *buf);
功能:获取文件属性
参数: path:文件路径名
buf:保存文件属性信息的结构体
返回值:成功:0
失败:-1
struct stat {
ino_t st_ino; /* inode号 ls -il */
mode_t st_mode; /* 文件类型和权限 */
nlink_t st_nlink; /* 硬链接数 */
uid_t st_uid; /* 用户ID */
gid_t st_gid; /* 组ID */
off_t st_size; /* 大小 */
time_t st_atime; /* 最后访问时间 */
time_t st_mtime; /* 最后修改时间 */
time_t st_ctime; /* 最后状态改变时间 */
};
打印inode号,链接数,大小:
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
struct stat st;
if(stat("a.c",&st)<0)
{
perror("stat err");
return -1;
}
printf("inode:%lu nlink:%d size:%ld\n",st.st_ino,st.st_nlink,
st.st_size);
return 0;
}