Linux 文件记录的时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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可以彻底改变你动文件的时间,你看到的就不是真的
[[email protected] ~]# 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
[[email protected] ~]# 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
。。。。。。。。
[[email protected] ~]# 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
[[email protected] ~]# 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
。。。。。。。。[[email protected] ~]# 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
[[email protected] ~]# chmod o+w 3.sql
[[email protected] ~]# 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
[[email protected] ~]#
[[email protected] ~]# 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.
[[email protected] ~]# 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
[[email protected] ~]# touch -a 3.sql ---加参数-a
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]#
[[email protected] ~]# touch 3.sql --木有加参数
[[email protected] ~]# 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
[[email protected] ~]#
本文出自 “运维邦” 博客,谢绝转载!
以上是关于Linux 文件记录的时间的主要内容,如果未能解决你的问题,请参考以下文章