歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux time屬性區別

Linux time屬性區別

日期:2017/2/27 16:05:17   编辑:Linux教程
Linux文件的change time和Modify time很多人很容易搞混淆,將ctime理解為create time(創建時間),那是瞎說的,Linux文件系統不會記錄create time的,除非文件創建過後,沒modify,沒change,那麼文件的創建時間和modify時間及change時間相同。
如:
[root@localhost ~]# stat lnmp.zip
  File: `lnmp.zip'
  Size: 66602649        Blocks: 130224     IO Block: 4096   regular file
Device: ca00h/51712d    Inode: 16528       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-06-20 12:01:40.000000000 +0800
Modify: 2012-04-23 10:09:07.000000000 +0800
Change: 2012-06-20 12:01:40.000000000 +0800
access time是文檔最後一次被讀取的時間。因此閱讀一個文檔會更新它的access時間,但它的modify時間和change時間並沒有變化。cat、more 、less、grep、sed、tail、head這些命令都會修改文件的access時間。
change time是文檔的索引節點(inode)發生了改變(比如位置、用戶屬性、組屬性等);
modify time是文本本身的內容發生了變化。[文檔的modify時間也叫時間戳(timestamp).]

如:
st_atime      Time when file data was last accessed. Changed by the following functions:creat(), mknod(), pipe(),utime(2), and read(2).

st_mtime      Time when data was last modified. Changed by the following functions: reat(), mknod(), pipe(), utime(),and write(2).

st_ctime      Time when file status was last changed. time of last modification of file status information.Changed by the following functions: chmod(), chown(), creat(),link(2), mknod(), pipe(), unlink(2), utime(), and write().
chmod, chown,create,mv等動作會將Linux文件的change time修改為系統當前時間
ls命令看到的是modify time
用wget等工具下載的文件,cahnge time不會被修改。
用vi等工具編輯一個文件保存後,modify time會被修改。
用ls -l命令不會修改文件的access time,但cat命令會修改access time。

如:
ls -lu (show files access time and sort by name)
ls -lc (show files change time and sort by name )
ls -l (show files modify time and sort by name )
如果加上-t參數,則按相應的時間排序後顯示。加上--time-style=long-iso,則會把文件的相應年月日時分秒time全部顯示出來。
touch命令能改變文件的access時間和modify時間為任意指定的時間。
modify time只能改變為系統時間,不能改變為任意時間。甚至用c程序來直接讀寫inode,也不會修改change time。
Copyright © Linux教程網 All Rights Reserved