码迷,mamicode.com
首页 > 系统相关 > 详细

修改linux文件的mtime

时间:2017-02-24 19:02:16      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:文件属性   dev   tar   默认   大小   修改   系统时间   tor   upd   

一.  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

修改linux文件的mtime

标签:文件属性   dev   tar   默认   大小   修改   系统时间   tor   upd   

原文地址:http://www.cnblogs.com/DillGao/p/6439836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!