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

}

编译运行:

相关推荐
白帽攻防录10 小时前
SRC 挖洞:DHCP 服务器上的四个 UAF,内网原生 RCE 怎么打域管
运维·服务器·网络安全·内网安全
万少10 小时前
Qoder sonus模型 20分钟,复刻 马斯克 飞天汽车
前端·后端·算法
七牛云行业应用10 小时前
Muse Spark Open 发布:Meta 称其为美国最强开放权重模型,816B 参数如何落地
算法
VidDown10 小时前
用户说“卡顿“,服务器一切正常:播放质量监测与 QoE 指标
运维·服务器·ffmpeg·音视频·视频
暖核11 小时前
从零搭建 Ubuntu24.04 服务器:虚拟机安装 + Netplan 静态 IP+SSH 远程登录
服务器·tcp/ip·ssh
瑞克-桑切斯11 小时前
13、DNS、DHCP 与 FTP 协议详解
linux·运维·云计算
程序员-Benothing11 小时前
Linux性能分析方法论:USE、RED、火焰图与perf实战
linux·运维·服务器
esop轻Mes看板亮灯分拣ESD静电安11 小时前
产线“最后一米”的破局密码:ESOP与MES的区别与深度协同
算法
问心无愧051311 小时前
[ACTF2020 新生赛]Exec
运维·服务器·笔记
微订校园外卖平台11 小时前
同城外卖跑腿平台需要服务器吗?交付方式、部署架构与上线核对
服务器·架构·github·外卖系统·本地生活·微订