atime, mtime, ctime

来源:互联网 发布:微信房卡麻将源码h5 编辑:程序博客网 时间:2024/04/29 03:57

在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# dateFri Jan  5 07:35:16 IST 2016ubuntu# chown root /tmp/file1ubuntu# ls -lc /tmp/file1-rw-r--r-- 1 root root 9 2016-01-15 07:35 /tmp/file1ubuntu# ls -lu /tmp/file1-rw-r--r-- 1 root root 9 2016-01-15 07:27 /tmp/file1ubuntu# ls -l /tmp/file1-rw-r--r-- 1 root root 9 2016-01-15 07:10 /tmp/file1

stat 查看时间戳

ubuntu# stat /tmp/file1File: `/tmp/file1'Size: 9             Blocks: 8          IO Block: 4096   regular fileDevice: 811h/2065d    Inode: 179420      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2016-01-15 07:27:51.000000000 +0100Modify: 2016-01-15 07:10:14.000000000 +0100Change: 2016-01-15 07:35:22.000000000 +0100
1 0
原创粉丝点击