每个文件都有两部分组成,数据和元数据,linux文件的三个时间就记录在元数据中,分别为atime(access time),ctime(status time),mtime(modify time)
三个时间的定义
mtime:当文件的内容数据改变时,会更新这个时间。(文件数据部分的内容)
ctime:当文件的状态改变时,会更新这个时间。(权限或属性)
atime:当数据被读取时,会更新这个时间。
可以通过stat命令查看文件的三个时间
[root@fox ~]# stat test File: ‘test’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 33594037 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2017-12-12 11:28:24.930239437 +0800 Modify: 2017-12-12 11:28:24.930239437 +0800 Change: 2017-12-12 11:28:24.930239437 +0800 Birth: -
三个时间的说明
- mtime
通过ls -l test查看test文件的mtime #ls -l显示出来的时间即为mtime
[root@fox ~]# ls -l test -rw-r--r--. 1 root root 0 Dec 12 11:28 test
改变其文件内容,发现mtime已经发生变化
[root@fox ~]# echo 111 > test [root@fox ~]# ls -l test -rw-r--r--. 1 root root 4 Dec 12 11:32 test
在mtime发生改变时,文件的ctime也会跟着改变,因为文件内容的改变,其Blocks,Size等元数据也发生了改变。
[root@fox ~]# stat test File: ‘test’ Size: 4 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 33594037 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2017-12-12 11:28:24.930239437 +0800 Modify: 2017-12-12 11:32:12.666074114 +0800 Change: 2017-12-12 11:32:12.666074114 +0800 Birth: -
- ctime
通过ls -l test,我们发现test文件的权限为644
[root@fox ~]# ls -l test -rw-r--r--. 1 root root 4 Dec 12 11:32 test
通过chmod 666 test,改变其权限,发下ctime发生了变化
[root@fox ~]# ls -l --time=ctime test -rw-r--r--. 1 root root 4 Dec 12 11:32 test [root@fox ~]# chmod 666 test [root@fox ~]# ls -l --time=ctime test -rw-rw-rw-. 1 root root 4 Dec 12 11:45 test
- atime
查看当文件被读取时,atime发生变化
[root@fox ~]# ls -l --time=atime test -rw-rw-rw-. 1 root root 4 Dec 12 11:28 test [root@fox ~]# cat test 111 [root@fox ~]# ls -l --time=atime test -rw-rw-rw-. 1 root root 4 Dec 12 11:48 test
当读取文件时,会修改atime
当改变文件内容时,会修改ctime和mtime
当改变权限等元数据信息时,会修改ctime