使用stat()函数的例子

代码:

复制代码
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>



int main(void)
{
	struct stat st;
	if(-1==stat("test.txt",&st))
	{
		printf("获得文件状态失败\n");
		return -1;
	}
	printf("包含此文件的设备ID: %d\n",st.st_dev);
	printf("此文件的节点: %d\n",st.st_ino);
	printf("此文件的保护模式: %d\n",st.st_mode);
        printf("此文件的硬件链接数: %d\n",st.st_nlink);
	printf("此文件的所有者ID: %d\n",st.st_uid);
        printf("此文件的所有者的组ID: %d\n",st.st_gid);

        printf("设备ID (如果此文件为特殊设备): %d\n",st.st_rdev);
        printf("此文件的大小: %d\n",st.st_size);
        printf("此文件的所在文件系统块大小: %d\n",st.st_blksize);
	printf("此文件的占用块数量: %d\n",st.st_blocks);
        printf("此文件的最后访问时间: %d\n",st.st_atime);
        printf("此文件的最后修改时间: %d\n",st.st_mtime);
        printf("此文件的最后状态改变时间: %d\n",st.st_ctime);

	return 0;

}

编译运行:

相关推荐
Re.不晚13 分钟前
挑战做100道力扣算法- DAY1
算法·leetcode·职场和发展
会编程的土豆17 分钟前
Go 模板初识
linux·运维·服务器
腾讯蓝鲸智云28 分钟前
标杆客户实践提炼:CFlow 版本价值流模板实战指南
运维·服务器·自动化·云计算·devops
蓝悦无人机35 分钟前
《Planning algorithms》读书笔记——第1章 引言
算法·读书笔记·规划算法·lavalle
阿标的博客1 小时前
Active Directory 组织单位和用户
服务器
Sagittarius_A*1 小时前
分组密码基础(二):Feistel 结构与 DES 的设计思想
算法·信息安全·密码学·des·数论
青山木1 小时前
Hot 100 --- 搜索插入位置
java·数据结构·算法·leetcode
Deryck_德瑞克1 小时前
【Nginx】配置差异分析
服务器·前端·nginx
alexwang2112 小时前
HDU 4348 详细题解
c++·算法·题解·hdu·主席树·可持久化数据结构·可持久化线段树
前端 贾公子2 小时前
第06章:结构化输出 (上)
java·服务器·前端