歡迎您光臨本站 註冊首頁

Linux文件的access time,change time,modify time

←手機掃碼閱讀     火星人 @ 2014-03-26 , reply:0

Linux文件的change time和Modify time很多人很容易搞混淆,有些Unix參考書都會寫錯(特別是翻譯的),將ctime理解為create time(創建時間),那是瞎說的,Linux文件系統不會記錄create time的,除非文件創建過後,沒modify,沒change,那麼文件的創建時間和modify時間及change時間相同。
QUOTE:
[root@test200 temp]# stat libnids-1.16.tar.gz
File: `libnids-1.16.tar.gz'
Size: 72309 Blocks: 152 IO Block: 4096 regular file
Device: 302h/770d Inode: 4113144 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2008-05-27 15:13:03.000000000 +0800
Modify: 2004-03-10 12:25:09.000000000 +0800
Change: 2008-05-27 14:18:18.000000000 +0800

access time是文檔最後一次被讀取的時間。因此閱讀一個文檔會更新它的access時間,但它的modify時間和change時間並沒有變化。cat、more 、less、grep、sed、tail、head這些命令都會修改文件的access時間。

change time是文檔的索引節點(inode)發生了改變(比如位置、用戶屬性、組屬性等);

modify time是文本本身的內容發生了變化。[文檔的modify時間也叫時間戳(timestamp).]
QUOTE:
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 fol-
lowing functions: creat(), 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。
QUOTE:
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。

[火星人 ] Linux文件的access time,change time,modify time已經有1854次圍觀

http://coctec.com/docs/linux/show-post-186508.html