• 修改linux文件的mtime


    一.  Linux 文件个时间信息 

      所有Unix 文件系统中的文件或文件夹有三个时间戳,分别为atime、ctime和mtime。

    1. atime 表示最后一次访问(仅仅访问,没有改动)文件的时间;
    2. mtime 表示最后一次修改文件的时间;
    3. ctime 表示最后一次对文件属性改变的时间,包括权限、大小、属性等。

      区别:

    区别 atime mtime ctime
    仅读取或访问文件(cat)  改变 不变 不变
    修改文件内容 不一定(vim 与echo就不一样) 改变 改变
    修改文件权限属性(chmod,chown) 不变 不变 改变

     

    二. 如何查看这些时间信息

    dill@ubuntu-vm:~/test/20170224$ stat file1 
      File: 'file1'
      Size: 20              Blocks: 8          IO Block: 4096   regular file
    Device: fc00h/64512d    Inode: 1447275     Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1000/    dill)   Gid: (    0/    root)
    Access: 2017-02-24 16:22:59.158209413 +0800
    Modify: 2017-02-24 16:22:31.134761578 +0800
    Change: 2017-02-24 16:22:31.134761578 +0800
     Birth: -

     

    三.  修改mtime

    dill@ubuntu-vm:~/test/20170224$ stat file1 
      File: 'file1'
      Size: 20              Blocks: 8          IO Block: 4096   regular file
    Device: fc00h/64512d    Inode: 1447275     Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1000/    dill)   Gid: (    0/    root)
    Access: 2017-02-24 16:22:59.158209413 +0800
    Modify: 2017-02-24 16:22:31.134761578 +0800
    Change: 2017-02-24 16:22:31.134761578 +0800
     Birth: -
    dill@ubuntu-vm:~/test/20170224$ touch -mt 1802241622 file1 
    dill@ubuntu-vm:~/test/20170224$ stat file1 
      File: 'file1'
      Size: 20              Blocks: 8          IO Block: 4096   regular file
    Device: fc00h/64512d    Inode: 1447275     Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1000/    dill)   Gid: (    0/    root)
    Access: 2017-02-24 16:22:59.158209413 +0800
    Modify: 2018-02-24 16:22:00.000000000 +0800
    Change: 2017-02-24 18:21:21.319212091 +0800
     Birth: -

      -m 参数指mtime,接下来的t和一串数字指我们想要更改成的timestamp

      1802241622 代表:

        18 ---> 2018年

        02 ---> 2月

        24 ---> 24号

        1622 --->时间16:22

     

     修改mtime到当前Linux时间

    dill@ubuntu-vm:~/test/20170224$ stat file1                                                                          
      File: 'file1'
      Size: 20              Blocks: 8          IO Block: 4096   regular file
    Device: fc00h/64512d    Inode: 1447275     Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1000/    dill)   Gid: (    0/    root)
    Access: 2017-02-24 16:22:59.158209413 +0800
    Modify: 2018-02-24 16:22:00.000000000 +0800
    Change: 2017-02-24 18:21:21.319212091 +0800
     Birth: -
    dill@ubuntu-vm:~/test/20170224$ touch file1 
    dill@ubuntu-vm:~/test/20170224$ stat file1 
      File: 'file1'
      Size: 20              Blocks: 8          IO Block: 4096   regular file
    Device: fc00h/64512d    Inode: 1447275     Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1000/    dill)   Gid: (    0/    root)
    Access: 2017-02-24 18:33:40.155812846 +0800
    Modify: 2017-02-24 18:33:40.155812846 +0800
    Change: 2017-02-24 18:33:40.155812846 +0800
     Birth: -

    touch 命令的默认行为就是更新一个文件的atime和mtime,改变到当前的系统时间。

     

    参考资料

    1. How to update atime and mtime for file in unix 
    2. Linux 文件3个时间点  A_carat_tear
  • 相关阅读:
    [杂谈]关于前端如何学习框架的一点牢骚
    【2018】面试复习大纲
    迟来的2017总结
    [转载并收藏]JavaScript 疲劳终极指南:我们行业的真相
    想做好产品,一定要成为自己产品的用户
    2017年个人提升计划
    Chrome新发现
    不要被所在的公司或企业绑架
    半夜不想睡有感
    2016年总结
  • 原文地址:https://www.cnblogs.com/DillGao/p/6439836.html
Copyright © 2020-2023  润新知