歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux系統文件時間屬性及配置修改

Linux系統文件時間屬性及配置修改

日期:2017/2/28 14:36:57   编辑:Linux教程

相信各位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

Copyright © Linux教程網 All Rights Reserved