Chinaunix首页 | 论坛 | 博客
  • 博客访问: 925429
  • 博文数量: 146
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 1523
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-29 10:32
文章分类

全部博文(146)

文章存档

2014年(2)

2013年(5)

2012年(4)

2011年(6)

2010年(30)

2009年(75)

2008年(24)

分类: LINUX

2009-07-31 18:22:00

描述一个文件更改时间时我们常常会看到mtime ,ctime,atime这几个字眼。
这里就这几个时间的问题我总结了一下。
access time  , atime在读取文件或执行文件时会修改
create time  , ctime在文件写入,更改所有者,权限。链接时文件的ctime会随之改变
modified time ,mtime 在文件写入时会改变。

ls -lu  或者 ls -l --time=atime 显示文件的atime
ls -lc 或者  ls -l --time=ctime 显示文件的ctime
ls -l    显示文件的mtime


    需要注意的是访问文件不一定atime会改变。因为:使用ext3文件系统的时候,如果在mount的时候使用了noatime参数那么就不会更新atime的 信息。而这是加了 noatime 取消了, 不代表真实情況.反正, 这三个 time stamp 都放在 inode 中.若 mtime, atime 修改, inode 就一定会改, 既然 inode 改了, 那 ctime 也就跟着要改了.之所以在 mount option 中使用 noatime, 就是不想 file system 做太多的修改, 而改善读取效能.

1》atime
along@along-laptop:~/code/shell/shell/along$ ls -lu
总用量 4
-rwxr--r-- 1 along along 22 2009-07-31 18:09 file
along@along-laptop:~/code/shell/shell/along$ cat file
#!/bin/bash
echo "ad"
along@along-laptop:~/code/shell/shell/along$ ls -lu
总用量 4
-rwxr--r-- 1 along along 22 2009-07-31 18:09 file      

 //上面看到访问了文件但是atime没有改变,

//我在实验的时候访问文件和执行文件 后有时文件的atime会改变,但多数时间文件的atime没有变化。这可能和系统的设置有关,具体原因我还是不太清楚。也许就是上面说的mount是的moatime选项的问题。

2》ctime

along@along-laptop:~/code/shell/shell/along$ ls -lc
总用量 4
-rwxr--r-- 1 along along 22 2009-07-31 18:09 file
along@along-laptop:~/code/shell/shell/along$ cat >> file
ad
^C
along@along-laptop:~/code/shell/shell/along$ ls -lc
总用量 4
-rwxr--r-- 1 along along 25 2009-07-31 18:16 file
along@along-laptop:~/code/shell/shell/along$ chmod 744 file
along@along-laptop:~/code/shell/shell/along$ ls -lc
总用量 4
-rwxr--r-- 1 along along 25 2009-07-31 18:17 file

//上面的看到我们向文件写入内容,和改变文件权限,后文件的ctime改变了

3》mtime
along@along-laptop:~/code/shell/shell/along$ ls -l
总用量 4
-rw-r--r-- 1 along along 25 2009-07-31 18:16 file
along@along-laptop:~/code/shell/shell/along$ cat >> file
adflsdf
^C
along@along-laptop:~/code/shell/shell/along$ ls -l
总用量 4
-rw-r--r-- 1 along along 33 2009-07-31 18:18 file

//上面的可以看到当我们修改文件内容是文件的mtime改变了


阅读(3290) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~