惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
V
V2EX
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
博客园 - 聂微东
博客园 - Franky
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
U
Unit 42
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
P
Proofpoint News Feed
L
LangChain Blog
博客园 - 叶小钗

博客园 - YiYezc

Django + Vue 学习日志( PART03:Django 模板) Django + Vue 学习日志(08Python 闭包和装饰器) Django + Vue 学习日志(07Python对象构造) Django + Vue 学习日志(06Python 对象相关) Django + Vue 学习日志(05CBV) Django + Vue 学习日志(04HttpRequest) Django+Vue 学习日志(03模板查找) Django+Vue 学习日志(02视图实例) Django+Vue 学习日志 Python的if语句 Python元组 Python列表操作 Python列表管理 Python列表元素管理 Python字符串 Python变量 centos安装autossh bash相关 Linux的bash快捷键 Vim程序编辑器 Linux下光盘镜像生成和刻录 Linux文件系统备份dump Linux下文件压缩与打包 Linux挂载 Linux磁盘分区 Linux文件访问和日志 block、inode、superblock详解 Linux文件系统的详解 Linux的权限对于文件与目录的意义 命令与文件的查询
ctime, atime与mtime释疑
YiYezc · 2016-02-21 · via 博客园 - YiYezc

UNIX系统将时间标记分成三种:

  1. atime( A ccess time):档案上次被读取的时间。
  2. ctime(status C hange time):档案的属性或内容上次被修改的时间。
  3. mtime( M odified time):档案的内容上次被修改的时间。

我们可以用一个很简单的script来印证这些东西。

#!/bin/bash
echo "ctime: $(ls -lc newFile | awk '{print $6, $7, $8}')"
echo "atime: $(ls -lu newFile | awk '{print $6, $7, $8}')"
echo "mtime: $(ls -l newFile | awk '{print $6, $7, $8}')"

exit 0;


姑且把他命名为showTime.sh

1. 假设我们建立一个新档:

touch newFile

执行showTime.sh,你会发现三种时间是相同的:

ctime: Nov 17 23:14
atime: Nov 17 23:14
mtime: Nov 17 23:14

2. 隔一分钟后,写入一些东西到档案里面:

echo "1st modified" > newFile

结果发现:

ctime: Nov 17 23:15
atime: Nov 17 23:14
mtime: Nov 17 23:15

3. 再隔一分钟后,读取这个档案但不更动内容:

cat newFile

结果发现:

ctime: Nov 17 23:15
atime: Nov 17 23:16
mtime: Nov 17 23:15

4. 在隔一分钟,仅修改属性:

chmod g+wx newFile

结果发现:

ctime: Nov 17 23:17
atime: Nov 17 23:16
mtime: Nov 17 23:15

从这个lab里我们可以得到以下结论:

  • ls -l所列出的长资讯,该时间是mtime。
  • 如果利用touch某档案,则三种时间属性均被更新。
  • 如果你修改了某一档案内容,则ctime与mtime会更新。
  • 如果某档案仅被读取或另存新档,则只有atime会被改变。
  • 如果你只改变档案属性(如权限、档名、所有人或是suid、acl、chattr等),则只有ctime被更新。
  • atime相较之下是最常变动的时间标记,可以将之关闭以增进I/O,特别是多人多工,小档案多以及laptop环境。filesystem设定里可以增加noatime属性,或是chattr +A固定住atime(chattr仅适用于ext2/3/4系列的filesystem)