linux文件时间戳
来源:互联网 发布:网络教育大专文凭 编辑:程序博客网 时间:2024/06/06 03:08
一 概要
atime: last access time, 记录的是最后访问文件的时间戳,主要是read文件内容,不包括读取inode的内容,也就是说ls,stat都不会改变atime,因为它们只读取了inode的内容,并没有读取文件的内容。
mtime: last modified time,记录的是最后修改文件的时间戳,主要是write文件内容,不包括修改inode内容。
ctime: last status changing time,记录的是最后文件状态改变的时间戳,包括文件内容和inode内容修改,但不包括atime和mtime的修改,也就是说atime变了,ctime不一定会改变。
这是man 2 stat查看到的部分内容:
Not all of the Linux file systems implement all of the time fields. Some file system types allow mounting in such a
way that file and/or directory accesses do not cause an update of the st_atime field. (See noatime, nodiratime, and
relatime in mount(8), and related information in mount(2).) In addition, st_atime is not updated if a file is opened
with the O_NOATIME; see open(2).
The field st_atime is changed by file accesses, for example, by execve(2), mknod(2), pipe(2), utime(2) and read(2)
(of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.
The field st_mtime is changed by file modifications, for example, by mknod(2), truncate(2), utime(2) and write(2) (of
more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that
directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.
The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode,
etc.).
从中可以得出如下信息: read大于0个字节时atime改变,write大于0个字节时mtime改变,也就是说以读写方式open文件时,所以的时间戳都不会改变,只有实际的读写操作时才会改变,记录的是最后操作的时间戳。
二 代码分析
分析内核代码:
do_generic_file_read()
{
...........
file_accessed(filp);
}
每次read后,都会调用file_accessed()更新atime.
__generic_file_aio_write()
{
...............
file_update_time();
}
每次write后,都会调用file_update_time()更新mtime和ctime,注意mtime改变时,ctime是一定会改变的。
三 atime
- linux文件时间戳
- linux文件时间戳
- linux文件时间戳
- Linux下递归修改文件时间戳
- 修改linux 文件的时间戳
- linux touch更改文件时间戳
- linux touch 修改文件的时间戳
- linux 文件日期转时间戳
- linux文件权限和文件时间戳
- linux修改文件时间
- Linux修改文件时间
- linux文件时间
- linux文件时间
- Linux文件时间属性
- linux 文件时间
- Linux 文件时间
- linux文件的时间
- 修改 linux 文件时间
- 提高应用程序可用性的五个要点
- hdu4638-tarjan求桥-Caocao's Bridges
- 面向对象
- 【文件上传】uploadify插件配合java的使用,可以图片,按照步骤可以复制粘贴直接运行,2017年
- C语言中基础的字符与字符串的输入与输出
- linux文件时间戳
- 011 Android programming 3rd 一个记录不良习惯的app
- 逆向助手的使用
- libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常
- svn解锁问题
- SpringMVC整合Hessian远程服务调用
- 角色权限中窗体的继承问题即窗体设计器打开异常现象
- 首信公司点赞Coremail邮件系统服务
- MySQL存储过程之游标实战