你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux系统文件时间属性及配置修改

[日期:2014-01-18] 来源:Linux社区  作者:cnlinux [字体: ]

相信各位Linux系统管理员经常接触到以下三种时间,ctime改变时间(change time)、mtime修改时间(modification time)、atime访问时间(access time),它们三个有什么区别呢?我们又该如何去对待它们呢?

首先我们需要知道如何查看相应的时间:

ll -c 查看ctime

ll 查看mtime

ll -u 查看atime
 

我的/tmp目录现在是空的,新建一个文件chaoxi,查看发现三个时间一致

[root@localhost tmp]# ls

[root@localhost tmp]# touch chaoxi

[root@localhost tmp]# ll

-rw-r--r--. 1 root root 0 1月 17 18:40 chaoxi

[root@localhost tmp]# ll -c

-rw-r--r--. 1 root root 0 1月 17 18:40 chaoxi

[root@localhost tmp]# ll -u

-rw-r--r--. 1 root root 0 1月 17 18:40 chaoxi
 

在/tmp/chaoxi中添加内容,ctime、mtime都发生变化

[root@localhost tmp]# echo "chaoxi" > /tmp/chaoxi

[root@localhost tmp]# ll

-rw-r--r--. 1 root root 7 1月 17 18:41 chaoxi

[root@localhost tmp]# ll -c

-rw-r--r--. 1 root root 7 1月 17 18:41 chaoxi

[root@localhost tmp]# ll -u

-rw-r--r--. 1 root root 7 1月 17 18:40 chaoxi
 

查看/tmp/chaoxi内容,只有atime变化

[root@localhost tmp]# cat chaoxi

chaoxi

[root@localhost tmp]# ll

-rw-r--r--. 1 root root 7 1月 17 18:41 chaoxi

[root@localhost tmp]# ll -c

-rw-r--r--. 1 root root 7 1月 17 18:41 chaoxi

[root@localhost tmp]# ll -u

-rw-r--r--. 1 root root 7 1月 17 18:41 chaoxi
 

修改/tmp/chaoxi文件权限,只有ctime变化

[root@localhost tmp]# chmod 755 chaoxi

[root@localhost tmp]# ll

-rwxr-xr-x. 1 root root 7 1月 17 18:41 chaoxi

[root@localhost tmp]# ll -c

-rwxr-xr-x. 1 root root 7 1月 17 18:42 chaoxi

[root@localhost tmp]# ll -u

-rwxr-xr-x. 1 root root 7 1月 17 18:41 chaoxi
 

到这里我们大致验证了这三个时间的一些变化规律,可以得到一个粗浅的结论:ctime是在写入文件、更改属主、权限或着链接时随Inode的内容更改而变化的;mtime是在写入文件时随文件内容的更改而变化的;atime是在读取文件或者执行文件时变化的。

那么,显而易见这三个时间的变化应该是很频繁的,我现在运维的有一个mysql集群,读写很频繁,可以在/etc/fstab使用noatime、nodiratime两个参数来避免文件系统不断记录文件的访问时间产生的磁盘I/O。如下:

/dev/mapper/VolGrouplv_root / ext4 noatime,nodiratime 0 0

linux
相关资讯       linux系统配置 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款