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
    
  • 相关阅读:
    vue框架,后端框架选型
    appium,元素定位和元素操作,使用uiautomatorviewer
    appium,参数化,数据驱动
    Qt 应用程序无法正常启动0xc000007b
    NOI2021 游记
    NOI 2021 游记
    NOI2021 看台风记
    NOI2021 部分题目题解
    NOI2021游记
    vectorized case branch
  • 原文地址:https://www.cnblogs.com/su-han/p/5602518.html
Copyright © 2011-2022 走看看