修改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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM