linux中文件访问时间的问题。。

nanbazhangbiao 2011-09-22 05:23:33
linux中有没有什么办法让一次访问文件后,文件的访问时间(st_atime)不变?
或者改变这个值?
...全文
114 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
programer.M 2011-09-22
  • 打赏
  • 举报
回复
路过学习
nanbazhangbiao 2011-09-22
  • 打赏
  • 举报
回复
我的代码是:
char path[];//文件路径
path=xxxxxxx;

struct utimbuf ub;

ut.actime=xxxxx;
ut.modtime=xxxxx;

utime(path,&ut);

这样下来。。文件的访问时间,不是我设的那个xxxxxx啊。。
而是当前的时间。。
chinasingle 2011-09-22
  • 打赏
  • 举报
回复
touch –t yyyymmddhhmm a.txt 取特定时间
qq120848369 2011-09-22
  • 打赏
  • 举报
回复

owenliang@localhost cAndCpp.dir]$ ls
csdnc csdn.c csdncpp csdn.cpp
[owenliang@localhost cAndCpp.dir]$ ls -l csdn.cpp
-rw-rw-r-- 1 owenliang owenliang 345 06-08 06:38 csdn.cpp
[owenliang@localhost cAndCpp.dir]$ ls -lu csdn.cpp
-rw-rw-r-- 1 owenliang owenliang 345 06-08 06:39 csdn.cpp
[owenliang@localhost cAndCpp.dir]$ ./csdn ./csdn.cpp
bash: ./csdn: 没有那个文件或目录
[owenliang@localhost cAndCpp.dir]$ ./csdnc ./csdn.cpp
current time is : Mon Jun 8 09:06:21 2009

[owenliang@localhost cAndCpp.dir]$ ls -l csdn.cpp
-rw-rw-r-- 1 owenliang owenliang 345 06-08 07:06 csdn.cpp
[owenliang@localhost cAndCpp.dir]$ ls -lu csdn.cpp
-rw-rw-r-- 1 owenliang owenliang 345 06-08 08:06 csdn.cpp
[owenliang@localhost cAndCpp.dir]$ date
2009年 06月 08日 星期一 09:07:06 CST
[owenliang@localhost cAndCpp.dir]$






1 #include <sys/types.h>
2 #include <utime.h>
3 #include <time.h>
4 #include <errno.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 int main(int argc,char* argv[])
10 {
11 if(argc==1)
12 {
13 fprintf(stderr,"no input....\n");
14 return 3;
15 }
16
17 time_t cur=time(NULL);
18
19 if(cur==-1)
20 {
21 fprintf(stderr,"%s\n",strerror(errno));
22 return 1;
23 }
24
25 printf("current time is : %s\n",ctime(&cur));
26
27 utimbuf ub;
28 ub.actime=cur-1*60*60; //访问时间1小时前
29 ub.modtime=cur-2*60*60; //修改时间2小时前
30
31 if(utime(argv[1],&ub)==-1)
32 {
33 fprintf(stderr,"%s\n",strerror(errno));
34 return 2;
35 }
36
37 return 0;
38 }


我也试了一下。

nanbazhangbiao 2011-09-22
  • 打赏
  • 举报
回复
我再问下。。问什么我用utime后,时间不是我设定的时间啊
是当前时间。。。
qq120848369 2011-09-22
  • 打赏
  • 举报
回复
man utime
nanbazhangbiao 2011-09-22
  • 打赏
  • 举报
回复
我知道touch可以改。。
但是我不是在命令行下需要这个工作。。
我是在程序中啊。。
用管道去调那个命令影响效率。。。
我是想问在程序中有什么方法。。
qq120848369 2011-09-22
  • 打赏
  • 举报
回复
ctime永远都是在真实的,atime和mtime都可以改,用touch改就可以了.
nanbazhangbiao 2011-09-22
  • 打赏
  • 举报
回复
我是说在程序中。。。不是用命令。
程序中有没有好的方法。。
子谋 2011-09-22
  • 打赏
  • 举报
回复
touch命令……

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧