含义:
modification time (mtime):
当该档案的『内容数据』变更时,就会更新这个时间!内容数据指的是档案的内容,而不是档案的属性或权限喔!
mtime的改变必然导致ctime的改变。
status time (ctime):
当该档案的『状态
(status)』改变时,就会更新这个时间,举例来说,像是权限与属性被更改了,都会更新这个时间啊。
access time (atime):
当『该档案的内容被取用』时,就会更新这个读取时间 (access)。举例来说,我们使用 cat 去读取
/etc/man.config , 就会更新该档案的 atime 了。
mtime (modification time ):在写入文件时随文件内容的更改而更改的时间。我们用ls
-l看到的时间,就是mtime
ctime (status
time):是在写入文件、更改所有者、权限或链接设置时随Inode的内容更改而更改的时间。相当于ls -l
–time=ctime所看到的时间
atime (access time):读取文件或者执行文件时更改的时间。也就是用ls -l
–time=atime看到的时间
这里还要补充一点:mount -o noatime(mount -o remount,atime /
可以在线重新挂载根目录)
可以选择不记录文件的atime的改变,这意味着什么呢?当你创建了这个文件后这个文件的atime就定格了,除非你用touch或者touch
-a强制刷新文件的atime。这样在可以在一定程度上提升文件系统的读写性能,特别是网站这种系统中在fstab里面加上noatime是个好主意
O(∩_∩)O
文件夹的 Access time,atime 是在读取文件或者执行文件时更改的(我们只cd进入一个目录然后cd
..不会引起atime的改变,但ls一下就不同了)。
文件夹的 Modified time,mtime
是在文件夹中有文件的新建、删除才会改变(如果只是改变文件内容不会引起mtime的改变,换句话说如果ls -f
的结果发生改变mtime就会被刷新。这里可能有人要争论了:我进入dd这个文件夹vi了一个文件然后退出,前后ls
-f
的结果没有改变但是文件夹的mtime发生改变了……这点请主意vi命令在编辑文件时会在本文件夹下产生一
个".file.swp"临时文件,该文件随着vi的退出而被删除……这就导致了mtime的改变
)。
文件夹的 Change time,ctime 基本同文件的ctime,其体现的是inode的change
time。
文件各种事件标记的显示方法
1 ls
ls -lc filename 列出文件的
ctime
ls -lu filename 列出文件的
atime
ls -l filename 列出文件的 mtime [root@Server ~]# ls -lc inbak.log ;ls -lu inbak.log ; ls -l
inbak.log ;
-rw-r--r--. 1 root root 14776 Aug 24 19:55 inbak.log
-rw-r--r--. 1 root root 14776 Sep 15 2007
inbak.log
-rw-r--r--. 1 root root 14776 Sep 15 2007
inbak.log
2 stat
使用stat命令可以查看三时间值:如 stat filename
[root@Server ~]# stat
inbak.log
File: `inbak.log'
Size: 14776 Blocks: 32 IO Block: 4096
regular file
Device: 802h/2050d Inode: 1445047 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2007-09-15 02:02:00.000000000 +0800
Modify: 2007-09-15 02:02:00.000000000 +0800
Change: 2012-08-24 19:55:17.251782812 +0800
3 touch
[root@www ~]# touch [-acdmt] 档案
选项与参数:
-a :仅修订 access time;
-c :仅修改档案的时间,若该档案不存在则不建立新档案;
-d :后面可以接欲修订的日期而不用目前的日期,也可以使用
--date="日期或时间"
-m :仅修改 mtime ;
-t
:后面可以接欲修订的时间而不用目前的时间,格式为[YYMMDDhhmm]
新建一个空的档案并观察时间
[root@www ~]# cd /tmp
[root@www tmp]# touch testtouch
[root@www tmp]# ls -l testtouch
-rw-r--r-- 1 root root 0 Sep 25 21:09 testtouch
# 注意到,这个档案的大小是 0 呢!在预设的状态下,如果 touch 后面有接档案,
# 则该档案的三个时间 (atime/ctime/mtime) 都会更新为目前的时间。若该档案不存在,
# 则会主动的建立一个新的空的档案喔!例如上面这个例子!
[root@Server ~]# ll install.log; ll
--time=atime install.log; ll --time=ctime install.log;
-rw-r--r--. 1 root root 14776 May 9 17:21
install.log
-rw-r--r--. 1 root root 14776 Aug 24 18:24 install.log
-rw-r--r--. 1 root root 14776 May 9 17:21
install.log
[root@Server ~]# cp -a install.log inbak.log
[root@Server ~]# ll inbak.log ; ll --time=atime inbak.log ; ll
--time=ctime inbak.log
-rw-r--r--. 1 root root 14776 May 9 17:21
inbak.log
-rw-r--r--. 1 root root 14776 Aug 24 18:24 inbak.log
-rw-r--r--. 1 root root 14776 Aug 24 19:52 inbak.log
#完全复制没有任何变化
[root@Server ~]# touch -d "2 days ago" inbak.log
[root@Server ~]# ll inbak.log ; ll --time=atime inbak.log ; ll
--time=ctime inbak.log
-rw-r--r--. 1 root root 14776 Aug 22 19:53 inbak.log
-rw-r--r--. 1 root root 14776 Aug 22 19:53 inbak.log
-rw-r--r--. 1 root root 14776 Aug 24 19:53 inbak.log
# 不过, ctime 并没有跟着改变喔!
[root@Server ~]# touch -t 0709150202 inbak.log
[root@Server ~]# ll inbak.log ; ll --time=atime inbak.log ; ll
--time=ctime inbak.log
-rw-r--r--. 1 root root 14776 Sep 15 2007
inbak.log
-rw-r--r--. 1 root root 14776 Sep 15 2007
inbak.log
-rw-r--r--. 1 root root 14776 Aug 24 19:55 inbak.log
# 注意看看,日期在 atime 与 mtime 都改变了,但是 ctime 则是记录目前的时间!
无论如何, touch 这个指令最常被使用的情况是:
建立一个空的档案;
将某个档案日期修订为目前 (mtime 与
atime)