概念
通过 stat filename
命令查看一个文件的三个时间属性
[root@centos01 ~]# stat 1.txt
File: `1.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 931337 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-02-27 22:20:10.803907698 +0800
Modify: 2016-02-27 22:20:10.803907698 +0800
Change: 2016-02-27 22:20:10.803907698 +0800
Access
后面的时间即为atime,文件被读会更改此属性
Modify
后面的时间即为mtime,文件内容改变会更改此属性
Change
后面的时间即为ctime,inode信息改变会更改此属性
如何更改atime、mtime、ctime
如上,1.txt
是新建的一个文件,初始状态其三个时间都一样的
- 当
cat 1.txt
后,atime 改变,mtime 和 ctime 不变
[root@centos01 ~]# cat 1.txt
[root@centos01 ~]# stat 1.txt
File: `1.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 931337 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:20:10.803907698 +0800
Change: 2016-02-27 22:20:10.803907698 +0800
- 当
echo "123" >> 1.txt
后,mtime 改变,ctime 改变,atime 不变
[root@centos01 ~]# echo "123" >> 1.txt
[root@centos01 ~]# stat 1.txt
File: `1.txt'
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 931337 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:29:36.153926096 +0800
Change: 2016-02-27 22:29:36.153926096 +0800
- 当
mv 1.txt 2.txt
/chmod 666 1.txt
等会变更inode信息的操作会使ctime改变,atime 和 mtime不变
[root@centos01 ~]# chmod 666 1.txt
[root@centos01 ~]# stat 1.txt
File: `1.txt'
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 931337 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:29:36.153926096 +0800
Change: 2016-02-27 22:30:44.079913921 +0800
- mtime 改变一定会导致 ctime 改变