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

推荐订阅源

博客园 - 司徒正美
Google Online Security Blog
Google Online Security Blog
博客园_首页
量子位
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
Vercel News
Vercel News
GbyAI
GbyAI
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
IT之家
IT之家
A
Arctic Wolf
P
Privacy International News Feed
G
GRAHAM CLULEY
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
The Blog of Author Tim Ferriss
AWS News Blog
AWS News Blog
A
About on SuperTechFans
P
Proofpoint News Feed
I
Intezer
月光博客
月光博客
Cloudbric
Cloudbric
Google DeepMind News
Google DeepMind News
T
Tor Project blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Securelist
Engineering at Meta
Engineering at Meta
爱范儿
爱范儿
F
Full Disclosure
V2EX - 技术
V2EX - 技术
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
人人都是产品经理
人人都是产品经理
C
Check Point Blog
I
InfoQ
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
F
Fortinet All Blogs
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - YiYezc

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的权限对于文件与目录的意义 命令与文件的查询 Linux下文件特殊权限 umask相关内容
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)