使用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;

}

编译运行:

相关推荐
海清河晏1113 小时前
数据结构 | 单循环链表
数据结构·算法·链表
莫回首�5 小时前
ubuntu 20.04 多网卡配置,遇到问题总结
linux·网络·ubuntu
网络安全许木5 小时前
自学渗透测试第11天(Linux压缩解压与磁盘管理)
linux·网络安全·渗透测试
问简7 小时前
虚拟化对比
服务器
wuweijianlove7 小时前
算法性能的渐近与非渐近行为对比的技术4
算法
_dindong8 小时前
cf1091div2 C.Grid Covering(数论)
c++·算法
AI成长日志8 小时前
【Agentic RL】1.1 什么是Agentic RL:从传统RL到智能体学习
人工智能·学习·算法
航Hang*8 小时前
Windows Server 配置与管理——第3章:文件系统管理
运维·服务器·windows·vmware
黎阳之光8 小时前
黎阳之光:视频孪生领跑者,铸就中国数字科技全球竞争力
大数据·人工智能·算法·安全·数字孪生
lifewange8 小时前
Linux ps 进程查看命令详解
linux·运维·服务器