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
    
  • 相关阅读:
    Linux链接库一(动态库,静态库,库放在什么路径下)
    scp指令的学习
    注册表语法
    汇编指令
    PS7.0快捷键和使用技巧
    Lrc歌词-开发标准
    VBS 创建快捷方式
    LDAP属性对照表
    按键精灵对VBS的支持
    英寸、磅等单位的换算
  • 原文地址:https://www.cnblogs.com/su-han/p/5602518.html
Copyright © 2011-2022 走看看