zoukankan      html  css  js  c++  java
  • 通过c程序更改文件的ctime和mtime

    通过c程序更改文件的ctime和mtime与某个文件相同

    源文件words.txt
    [root@bogon ~]# ll words.txt ;ll words.txt -u
    -rw-r--r-- 1 root root 740 7月  14 2007 words.txt
    -rw-r--r-- 1 root root 740 6月  12 09:33 words.txt
    新建测试文件text.txt
    [root@bogon ~]# touch text.txt
    [root@bogon ~]# ll text.txt;ll text.txt -u
    -rw-r--r-- 1 root root 23 6月  21 09:20 text.txt
    -rw-r--r-- 1 root root 23 6月  21 09:20 text.txt
    创建c程序
    [root@bogon ~]# vim atimemtime.c 
    
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <utime.h>
    /*#include <quit.h>*/
    
    int main(int argc,char **argv) {
       struct stat statbuf;
       struct utimbuf timebuf;
    
       lstat(argv[1],&statbuf);
       timebuf.actime=statbuf.st_atime;
       timebuf.modtime=statbuf.st_mtime;
       utime(argv[2],&timebuf);
       close(argv[2]);
    
    }
    将c文件编译,编译后的文件名为testc
    [root@bogon ~]# gcc -o testc atimemtime.c 
    修改测试文件text.txt的时间为words.txt的访问时间和修改时间
    [root@bogon ~]# ./testc words.txt text.txt
    [root@bogon ~]# ll text.txt;ll text.txt -u
    -rw-r--r-- 1 root root 23 7月  14 2007 text.txt
    -rw-r--r-- 1 root root 23 6月  12 09:33 text.txt
    
  • 相关阅读:
    ORACLE DROP TABLE和truncate table的区别
    C#版链表加强版
    C#版栈
    再谈为什么要使用MONO
    流浪猫伏击大白鹅
    编写ASP.NET复合控件实例
    C# 大文件拷贝
    关于团队项目构架设计的疑问
    在Windows平台下使用MONO
    C#版链表
  • 原文地址:https://www.cnblogs.com/su-han/p/5602518.html
Copyright © 2011-2022 走看看