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

}

编译运行:

相关推荐
CoderYanger7 小时前
Java EE 进阶:14.案例综合练习-博客系统(第二弹):博客详情+令牌技术
服务器·前端·spring boot·后端·spring·java-ee·github
IvanCodes8 小时前
模型如何自我改进?拆解 RSI 的模型权重与 Harness 两条路线
人工智能·算法·ai·论文·agent·rsi
Rsingstarzengjx8 小时前
第三十九章 Linux PWM 驱动实验
linux·运维·服务器
罗西的思考8 小时前
【轻量化复刻大模型 / KIMI K3】MXFP4 / MXFP8 量化感知训练(QAT)& 演示
人工智能·算法·机器学习
SeanQhl9 小时前
BoostKit 环境准备
linux·openeuler·鲲鹏·boostkit·软件源
笔记本note11 小时前
Linux 内存管理
linux·服务器·内存管理
郝学胜-神的一滴11 小时前
Effective STL 条款 14:用扩容函数避免重新分配
linux·开发语言·网络·数据结构·c++·单片机
旖旎夜光12 小时前
LeetCode 493: 翻转对 (归并排序) —— 题解
c++·笔记·学习·算法·leetcode·排序算法
阿enna12 小时前
检测指标入门:IoU、Precision、Recall与mAP
人工智能·深度学习·算法·yolo·目标检测·计算机视觉·cnn
GeW12 小时前
入行 Linux 与数据库运维:一条路径、三项习惯、一个考证观
linux·数据库