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

Linux 文件记录的时间

时间:2016-08-29 00:10:40      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:regular   access   change   touch   modify   linux   

    生产发现一个问题,找到根源是因为文件被修改了,然后通过查看修改的时间,权限用户,找到操作的机器,其中发现一个点就是Linux文件时间记录,有三个Access(访问),Modfiy(vi编辑),Change(修改权限)

常用的查看为stat filename和ls -l --full-time filename

1,当我们仅仅只是读取文件时,access time 改变,而modify,change time 不会改变

2,当修改文件时,access,modify,change time 都会跟着改变

3,当修改文件属性时,change time 改变,而access,modify time 不变

所以掌握了这一点,通过touch可以彻底改变你动文件的时间,你看到的就不是真的

[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2126            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652821      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:08:26.571999874 +0800   --精确到毫秒级别
Modify: 2016-08-28 18:08:26.571999874 +0800
Change: 2016-08-28 18:08:26.575999780 +0800

[root@localhost ~]# cat 3.sql
- MySQL dump 10.13  Distrib 5.5.22, for Linux (i686)
--
-- Host: 192.168.4.11    Database: test
-- ------------------------------------------------------
-- Server version       5.5.22-log
。。。。。。。。
[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2126            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652821      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:18:50.937999994 +0800   --因为刚才执行了cat 所以只改变
Modify: 2016-08-28 18:08:26.571999874 +0800
Change: 2016-08-28 18:08:26.575999780 +0800

[root@localhost ~]# vi 3.sql
- MySQL dump 10.13  Distrib 5.5.22, for Linux (i686)
--
-- Host: 192.168.4.11    Database: test
-- ------------------------------------------------------
-- Server version       5.5.22-log
。。。。。。。。[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:20:36.679998313 +0800---可以看到vi时都变了
Modify: 2016-08-28 18:20:36.679998313 +0800
Change: 2016-08-28 18:20:36.696998878 +0800

[root@localhost ~]# chmod o+w 3.sql
[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0757/-rwxr-xrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:20:36.679998313 +0800
Modify: 2016-08-28 18:20:36.679998313 +0800
Change: 2016-08-28 18:21:43.217999570 +0800
[root@localhost ~]#


[root@localhost ~]# info touch --这个东西不仅可以创建文件还可以更改文件时间

time stamps.

   The program accepts the following options.  Also see *note Common
options::.

`-a‘
`--time=atime‘
`--time=access‘
`--time=use‘

     Change the access time only.


[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0757/-rwxr-xrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:24:23.473989642 +0800
Modify: 2016-08-28 18:24:23.473989642 +0800
Change: 2016-08-28 18:24:23.473989642 +0800
[root@localhost ~]#
touch -a 3.sql ---加参数-a
[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0757/-rwxr-xrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:24:34.580998824 +0800
Modify: 2016-08-28 18:24:23.473989642 +0800
Change: 2016-08-28 18:24:34.580998824 +0800


[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0757/-rwxr-xrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:24:34.580998824 +0800
Modify: 2016-08-28 18:24:23.473989642 +0800
Change: 2016-08-28 18:24:34.580998824 +0800
[root@localhost ~]#
[root@localhost ~]#
touch 3.sql  --木有加参数
[root@localhost ~]# stat 3.sql
  File: `3.sql‘
  Size: 2127            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 652820      Links: 1
Access: (0757/-rwxr-xrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-08-28 18:28:26.230998361 +0800
Modify: 2016-08-28 18:28:26.230998361 +0800
Change: 2016-08-28 18:28:26.230998361 +0800
[root@localhost ~]#


本文出自 “运维邦” 博客,谢绝转载!

Linux 文件记录的时间

标签:regular   access   change   touch   modify   linux   

原文地址:http://aklaus.blog.51cto.com/9724632/1843630

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