Linux操作系统下文件的三个时间属性atime 、ctime 、mtime
2016-08-22 14:05
465 查看
Linux操作系统下有三个主要的时间属性,分别是ctime(change time),atime(accsess time),mtime(modify time),下面一一解释。
atime: access time,是在读取文件或者执行文件时更改,即文件最后一次被读取时间 说明: atime Time when file data was last accessed ,changded by the following funtions: creat ,mknod,pipe,utime,read,`
ctime:Change time,是在写入文件、更改所有者、权限或链接设置时随 Inode 的内容更改而更改,即文件状态最后一次被改变的时间。 说明:ctime Time when file status was last changed. Changed by the following functions: chmod(), chown(), creat(),link(), mknod(), pipe(), unlink(2),utime(), and write().
mtime:Modified time,是在写入文件时随文件内容的更改而更改,是指文件内容最后一次被修改的时间。 说明: mtime Time when data was last modified. Changed by the fol- lowing functions: creat(), mknod(), pipe(), utime(), and write().
mtime和ctime的区别在于,只有修改了文件的内容,才会更新文件的mtime,而对文件更名,修改文件的属主等操作,只会更新ctime。 举例说明: 对文件进行mv操作,mtime不变,ctime更新;编辑文件内容,mtime和ctime同时修改。其他操作的影响,可以自己试验。但是我发现对文件执行touch操作,会同时修改mtime和ctime,所以具体修改哪个时间,还取决于不同命令自己的实现; atime, 这个就是每次查看文件内容的时候会更新。比如cat操作,而ls操作是不会更新的。 可以通过 ls(l) 命令来查看,具体如下: ls -lc filename 列出文件的 ctime ls -lu filename 列出文件的 atime ls -l filename 列出文件的 mtime
注意:
1、修改是文本本身的内容发生了变化(mtime)
改变是文件的索引节点发生了改变(ctime)
2、如果修改了文件内容,则同时更新ctime和mtime
3、如果只改变了文件索引节点,比如修改权限,则只是改变了ctime
4、如果使用ext3文件系统的时候,在mount的时候使用了noatime参数则不会更新atime的信息,即访问文件之后atime不会被修改,而这个不代表真实情况
小知识:这三个 time stamp 都放在 inode 中。若mtime,atime修改, inode 就一定会改,相应的inode改了,那ctime 也就跟着要改了,之所以在mount option中使用 noatime, 就是不想 file system 做太多的修改, 从而改善读取性能.
例子 1:# echo "Hello World" >> myfile atime不变,同时改变了ctime和mtime 2:# cat myfile ctime和mtime不变,只改变atime # ls myfile ctime和mtime以及atime都不变 3:# chmod u+x myfile mtime和atime不变,只改变ctime 4:# mv myfile ../ mtime和atime不变,只改变ctime
在网上找到了一个表,列出了常见的系统调用对这几个时间的影响,包括对父目录的影响
相关文章推荐
- Linux下文件系统的三个主要时间属性atime、ctime、mtime
- Linux系统文件有三个主要的时间属性,分别是ctime(change time), atime(access time), mtime(modify time)
- Linux下关于文件的三个时间(atime/ctime/mtime)
- linux下文件的三个时间 atime,ctime,mtime及其如何改变
- Linux文件和目录的操作(十二) 三个时间 atime mtime ctime
- Linux下文件的三个时间:ctime、mtime、atime的区别
- Linux下文件的三个时间:ctime、mtime、atime的区别
- Linux下文件的三个时间(Atime,Mtime,Ctime)
- Linux下文件的三个时间(Atime,Mtime,Ctime)
- linux下文件的三个时间(Atime ,Mtime,Ctime)
- Linux下文件的三个时间(Atime,Mtime,Ctime)
- Linux下文件的三个时间戳:atime,mtime,ctime
- Linux下的三个时间参数:atime 、mtime和ctime
- 文件的时间属性atime,mtime,ctime
- 4.18 st_atime、st_mtime和st_ctime成员-文件时间属性
- 【随笔】Linux文件的三个时间属性
- Linux文件时间详解ctime、mtime、atime【转】
- Linux下文件的Access time,Modify time, Change time三个时间的概念、区别和联系。
- 三个时间属性atime、mtime、ctime
- 【随笔】Linux文件的三个时间属性