天高云淡 发表于 2018-5-19 13:01:38

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可以彻底改变你动文件的时间,你看到的就不是真的

  # 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
# cat 3.sql
- MySQL dump 10.13Distrib 5.5.22, for Linux (i686)
--
-- Host: 192.168.4.11    Database: test
-- ------------------------------------------------------
-- Server version       5.5.22-log
。。。。。。。。
# 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
  # vi 3.sql
- MySQL dump 10.13Distrib 5.5.22, for Linux (i686)
--
-- Host: 192.168.4.11    Database: test
-- ------------------------------------------------------
-- Server version       5.5.22-log
。。。。。。。。# 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
# chmod o+w 3.sql
# 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
#

  

  # 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.
  
  # 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
# touch -a 3.sql ---加参数-a
# 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
  

  # 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
#
# touch 3.sql--木有加参数
# 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
#
页: [1]
查看完整版本: Linux 文件记录的时间