您的位置:首页 > 其它

atime、mtime、ctime讲解

2014-03-30 11:38 232 查看
linux下文件没有创建时间,只有atime、mtime、ctime三个时间。
命令:stat filename 查看三个时间
[root@server test]# stat file
File: `file'
Size: 73 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279310 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-03-30 03:20:44.691532547 +0800
Modify: 2014-03-30 03:20:44.691532547 +0800
Change: 2014-03-30 03:20:44.720532697 +0800

其中:atime(access time)在读取文件或者执行文件时会更改变。
mtime(modify time)在文件内容改变或执行文件时会更改变。
ctime(change time)在写入文件更改文件所有者、权限或链接时会改变。
例子:
[root@server test]# cat file
The purpose of this document is to compare the atime mtime ctime changes
[root@server test]# stat file
File: `file'
Size: 73 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279310 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-03-30 03:23:59.676533615 +0800 //atime改变
Modify: 2014-03-30 03:20:44.691532547 +0800
Change: 2014-03-30 03:20:44.720532697 +0800

[root@server test]# vim file //添加了一行
[root@server test]# stat file
File: `file'
Size: 102 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279309 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-03-30 03:26:37.847534204 +0800 //三个时间都发生改变
Modify: 2014-03-30 03:26:37.847534204 +0800
Change: 2014-03-30 03:26:37.859533622 +0800

[root@server test]# chmod 777 file
[root@server test]# stat file
File: `file'
Size: 102 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279309 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-03-30 03:26:37.847534204 +0800
Modify: 2014-03-30 03:26:37.847534204 +0800
Change: 2014-03-30 03:27:20.338530935 +0800 //ctime改变

[root@server test]# chown user1 file
[root@server test]# stat file
File: `file'
Size: 102 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279309 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 501/ user1) Gid: ( 0/ root)
Access: 2014-03-30 03:26:37.847534204 +0800
Modify: 2014-03-30 03:26:37.847534204 +0800
Change: 2014-03-30 03:30:41.599532182 +0800 //ctime改变

[root@server test]# ln file file.link
[root@server test]# stat file
File: `file'
Size: 102 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279309 Links: 2
Access: (0777/-rwxrwxrwx) Uid: ( 501/ user1) Gid: ( 0/ root)
Access: 2014-03-30 03:26:37.847534204 +0800
Modify: 2014-03-30 03:26:37.847534204 +0800
Change: 2014-03-30 03:31:49.151541931 +0800 //ctime改变

[root@server test]# echo "add one line" >>file
[root@server test]# stat file
File: `file'
Size: 115 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 279309 Links: 2
Access: (0777/-rwxrwxrwx) Uid: ( 501/ user1) Gid: ( 0/ root)
Access: 2014-03-30 03:26:37.847534204 +0800
Modify: 2014-03-30 03:34:11.254531631 +0800 //mtime、ctime都改变
Change: 2014-03-30 03:34:11.254531631 +0800

本文出自 “linux成长之路” 博客,请务必保留此出处http://linuxlovers.blog.51cto.com/6787002/1386830
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: