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

}

编译运行:

相关推荐
GeW6 小时前
新质生产力路线图Linux、数据库、国产化替代一次讲透
linux
zyl7658 小时前
FlashAttention 详解:从 GPU 硬件、普通 Attention 到分块计算与 Online Softmax
算法
aningx8 小时前
cachyos 从 GRUB 切换到 rEFInd
linux
第404号工位10 小时前
40块钱二手瘦客户端,如何跑满家庭物联网中枢?(拒绝Docker爆盘实录)
linux·架构·node.js
对象存储与RustFS10 小时前
网盘限速逼你开会员?用 RustFS 自己搭一个不限速的“私人网盘
服务器·后端·docker
骑着蜗牛撵大象32711 小时前
Linux 进程间通信之管道:从 pipe() 的内核语义到 FIFO 落地排错
android·java·linux·系统编程·fifo·管道·进程间通信
爱读书的小胖11 小时前
LeetCode 122:买卖股票的最佳时机 II(C)解题分析
算法
结局无敌11 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
..Dauntless..12 小时前
【Linux】一切皆文件和缓冲区
linux·运维·服务器
裕晟资质规划12 小时前
三类资质变更报告时限差在哪?军工 15 日、集成印制 10 日
大数据·服务器·网络