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

}

编译运行:

相关推荐
不瘦80斤不改名几秒前
Python 日志(logging)全解析
服务器·python·php
多米Domi0115 分钟前
0x3f 第19天 javase黑马81-87 ,三更1-23 hot100子串
python·算法·leetcode·散列表
..过云雨10 分钟前
17-2.【Linux系统编程】线程同步详解 - 条件变量的理解及应用
linux·c++·人工智能·后端
莫逸风12 分钟前
【局域网服务方案】:无需找运营商,低成本拥有高性能服务器
运维·服务器
历程里程碑20 分钟前
滑动窗口最大值:单调队列高效解法
数据结构·算法·leetcode
課代表40 分钟前
从初等数学到高等数学
算法·微积分·函数·极限·导数·积分·方程
ullio44 分钟前
arc206d - LIS ∩ LDS
算法
oMcLin1 小时前
CentOS 7 频繁出现 “Connection Refused” 错误的原因分析与解决
linux·运维·centos
等等小何1 小时前
leetcode1593拆分字符串使唯一子字符串数目最大
算法
小李独爱秋1 小时前
计算机网络经典问题透视:常规密钥体制与公钥体制最主要的区别是什么?—— 一文带你从“钥匙”看懂现代密码学核心
服务器·网络·tcp/ip·计算机网络·密码学