[原创]LINUX下的文件时间克隆程序
文章作者:pt007[at]vip.sina.com信息来源:邪恶八进制信息安全团队([url]www.eviloctal.com[/url])
注:文章首发I.S.T.O信息安全团队,后由原创作者友情提交到邪恶八进制信息安全团队技术讨论组。I.S.T.O版权所有,转载需注明作者。[code]
/*
程序:LINUX下的文件时间克隆
作者:pt007@vip.sina.com,貌似需要文件所有者或者root权限才能运行
测试:
gcc -o touch touch.c
touch newfile oldfile
*/
#include "stdio.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utime.h>
int main (int argc,char **argv)
{
int i;
struct stat statbuf;
struct utimbuf timebuf;
/* Determine the options. */
if (argc!=3) {
printf("Usage: touch newfile oldfile\n");
return 0;
}
if(stat(argv[2],&statbuf)<0) //fetch currnet times
{
printf("%s,stat error!\n",argv[2]);
return 0;
}
timebuf.actime=statbuf.st_atime;
timebuf.modtime=statbuf.st_mtime;
if(utime(argv[1],&timebuf)<0) //modify time
{
printf("%s:utime error!\n",argv[1]);
return 0;
}
printf("Setting file times sucess!\n");
return 0;
}
[/code]
[[i] 本帖最后由 pt007 于 2008-3-26 12:43 编辑 [/i]] 顶~~ PT! 直接做一个修改时间的哇~ 别克聋 有点麻烦!还需要一个被克隆的对象 touch -r 一下不就行了
touch -r 具有你希望改成的时间的文件 你要改变的文件
不会用自己man 去 [quote]原帖由 [i]kj021320[/i] 于 2008-3-26 13:13 发表 [url=https://forum.eviloctal.com/redirect.php?goto=findpost&pid=140473&ptid=32658][img]images/common/back.gif[/img][/url]
顶~~ PT! 直接做一个修改时间的哇~ 别克聋 有点麻烦!还需要一个被克隆的对象 [/quote]
最好的还是用克隆对象的,因为在大多数的时候,我们不知道该设置成什么时间,直接设置成和/bin/ls一样就成 [quote]原帖由 [i]xi4oyu[/i] 于 2008-3-26 13:57 发表 [url=https://forum.eviloctal.com/redirect.php?goto=findpost&pid=140477&ptid=32658][img]images/common/back.gif[/img][/url]
touch -r 一下不就行了
touch -r 具有你希望改成的时间的文件 你要改变的文件
不会用自己man 去 [/quote]
我把wget_err用/bin/ls touch -r了
但touch好像改不掉ctime,楼主的代码也改不掉ctime
[quote][root@localhost tmp]# ll
total 40K
drwxrwxrwt 3 root root 4.0K 2008-07-21 21:56:27.000000000 +0800 .
drwxr-xr-x 25 root root 4.0K 2008-06-19 09:57:24.000000000 +0800 ..
drwxrwxrwt 2 root root 4.0K 2008-05-20 05:59:28.000000000 +0800 .ICE-unix
-rw-r--r-- 1 root root 13K 2008-07-02 11:11:31.000000000 +0800 index.dat_bak
srwxrwxrwx 1 mysql mysql 0 2008-05-20 05:59:42.000000000 +0800 mysql.sock
-rw-r----- 1 root root 468 2006-11-28 00:47:11.000000000 +0800 wget_err
[root@localhost tmp]# ll wget_err /bin/ls
-rwxr-xr-x 1 root root 92K 2006-11-28 00:47:11.000000000 +0800 /bin/ls
-rw-r----- 1 root root 468 2006-11-28 00:47:11.000000000 +0800 wget_err
[root@localhost tmp]# ls --time=ctime -l /bin/ls wget_err
-rwxr-xr-x 1 root root 93560 Apr 19 04:04 /bin/ls
-rw-r----- 1 root root 468 Jul 21 21:57 wget_err
[root@localhost tmp]# ls --time=atime -l /bin/ls wget_err
-rwxr-xr-x 1 root root 93560 Jul 21 21:59 /bin/ls
-rw-r----- 1 root root 468 Jul 21 21:57 wget_err[/quote]
[[i] 本帖最后由 EastNoFail 于 2008-7-21 22:02 编辑 [/i]] ctime要加-m选项。看看man手册,呵呵
touch -m -a -r 1 2
atime的修改要通过修改系统时间才行,你看看touch2.c的代码 不过有的分区挂载的时候会加上 noatime选项
[[i] 本帖最后由 xi4oyu 于 2008-7-21 23:20 编辑 [/i]] [quote]原帖由 [i]xi4oyu[/i] 于 2008-7-21 23:19 发表 [url=https://forum.eviloctal.com/redirect.php?goto=findpost&pid=145930&ptid=32658][img]images/common/back.gif[/img][/url]
ctime要加-m选项。看看man手册,呵呵
touch -m -a -r 1 2
atime的修改要通过修改系统时间才行,你看看touch2.c的代码 不过有的分区挂载的时候会加上 noatime选项 ... [/quote]
touch -amc -r 1 2
我是这么操作的,你可以试试的。 没多大用处,直接touch -r都搞定了,修改文件时间touch -t不就行了,用工具来的还麻烦。
页:
[1]