在Linux中,所有的文件和目录都有三种最常见的时间戳:
- access time – atime 读取时间
- change time – ctime 改变时间
- modify time – mtime 修改时间
那么,这三个时间的具体含义和区别是什么呢?
atime
Access time 显示的是文件最近一次被读取的时间
mtime
Modify time 显示的是文件最近一次【内容】被修改的时间
ctime
Change time,当该档案的『状态 (status)』改变时,就会更新这个时间,举例来说,象是权限与属性被更改了,都会更新这个时间。
ls查看时间戳
ls -l 默认查看的是mtime:
ubuntu# ls -l /tmp/file1
-rw-r--r-- 1 greys root 9 2016-01-15 07:10 /tmp/file1
想查看 atime 使用 ls -lu:
ubuntu# ls -lu /tmp/file1
-rw-r--r-- 1 greys root 9 2016-01-15 07:27 /tmp/file1
想查看 ctime 使用 ls -lc:
ubuntu# ls -lc /tmp/file1
-rw-r--r-- 1 greys root 9 2016-01-15 07:31 /tmp/file1
为了验证上面说的内容,下面我来修改一下该文件的owner,看看三个时间戳的变化:
ubuntu# date
Fri Jan 5 07:35:16 IST 2016
ubuntu# chown root /tmp/file1
ubuntu# ls -lc /tmp/file1
-rw-r--r-- 1 root root 9 2016-01-15 07:35 /tmp/file1
ubuntu# ls -lu /tmp/file1
-rw-r--r-- 1 root root 9 2016-01-15 07:27 /tmp/file1
ubuntu# ls -l /tmp/file1
-rw-r--r-- 1 root root 9 2016-01-15 07:10 /tmp/file1
stat 查看时间戳
ubuntu# stat /tmp/file1
File: `/tmp/file1'
Size: 9 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 179420 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-01-15 07:27:51.000000000 +0100
Modify: 2016-01-15 07:10:14.000000000 +0100
Change: 2016-01-15 07:35:22.000000000 +0100
本文详细解释了Linux系统中文件的三种时间戳:atime、mtime和ctime的含义及区别,并通过实例展示了如何使用ls和stat命令查看这些时间戳。
468

被折叠的 条评论
为什么被折叠?



