atime, mtime, ctime

本文详细解释了Linux系统中文件的三种时间戳:atime、mtime和ctime的含义及区别,并通过实例展示了如何使用ls和stat命令查看这些时间戳。

在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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值