標籤:blog http io ar sp for strong on 檔案
linux下的-atime,-ctime,-mtime含義
我們經常會在論壇或者群裡面被問到,在linux或者unix下如何查看某檔案的建立日期?
經常又會有人說用find命令加選項-ctime,其實這裡的-ctime並非是create time,而是change time。
在linux或者unix這類作業系統,並沒有為我們儲存檔案的建立日期。
[@[email protected]]
linux下的-atime,-ctime,-mtime含義
我們經常會在論壇或者群裡面被問到,在linux或者unix下如何查看某檔案的建立日期?
經常又會有人說用find命令加選項-ctime,其實這裡的-ctime並非是create time,而是change time。
在linux或者unix這類作業系統,並沒有為我們儲存檔案的建立日期。
我們可以先來看看linux系統裡檔案的狀態資訊,下面這個檔案是我一周前建立的:
[[email protected] ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 一般檔案
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-17 15:22:45.000000000 +0800
可以看到,檔案狀態裡有三個時間,分別是access,modify,change。
下面我們再來看看find命令下的這幾個選項:
[[email protected] admin]$ man find
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional
part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-mtime n
File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file
modification times.
-ctime n
File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file
status change times.
發現三個時間正好與檔案的三個時間狀態相同,而且協助也已經很明顯的告訴了我們其具體含義:
atime的意思是access time,即檔案的最近的一次訪問時間,+n意思為尋找n天以前的檔案,-n為尋找n天以內的檔案
例如有一個檔案data4.txt,查看一下它的狀態:
[[email protected] ~]$ stat data4.txt
File: `data4.txt‘
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458037 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-10 11:46:05.000000000 +0800Modify: 2012-07-10 11:44:37.000000000 +0800
Change: 2012-07-10 11:44:37.000000000 +0800
我們來查看一下它的內容:
[[email protected] ~]$ more data4.txt
"SCOTT",12,"F444"
"BRENTT",43,"54GSS"
"SYS",4566
再來看看檔案的狀態:
[[email protected] ~]$ stat data4.txt
File: `data4.txt‘
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458037 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-22 23:21:10.000000000 +0800Modify: 2012-07-10 11:44:37.000000000 +0800
Change: 2012-07-10 11:44:37.000000000 +0800
可以發現,只要你查看了檔案的內容,無論是more,cat,vi,那麼檔案的access time都會更新。
mtime比較好理解,為modify time,即檔案資料最新的修改時間,指的就是檔案內容的最新修改時間。
[[email protected] ~]$ stat ctl1.txt
File: `ctl1.txt‘
Size: 288 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458031 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-22 23:46:05.000000000 +0800
Modify: 2012-07-10 11:44:05.000000000 +0800Change: 2012-07-10 11:44:05.000000000 +0800
對檔案進行一下編輯:
[[email protected] ~]$ echo "" >>ctl1.txt
[[email protected] ~]$ stat ctl1.txt
File: `ctl1.txt‘
Size: 291 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458070 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-22 23:46:05.000000000 +0800
Modify: 2012-07-22 23:46:31.000000000 +0800
Change: 2012-07-22 23:46:31.000000000 +0800發現檔案的modify和change時間都變化了,change time 下面討論。
ctime的意思是change time,檔案狀態最新改變的時間。是檔案的status change time,何為檔案的status呢?
我們都知道檔案有一些個基本的屬性,許可權,使用者,組,大小,修改時間等,只要是這些資訊變化了,那麼ctime都會發生變化,
所以上面修改檔案內容時為何ctime會變化,因為其mtime已經變化了,mtime也是檔案狀態的一個。
檔案狀態可以通過ls -l 查看:
[[email protected] ~]# ls -l 3
-rw-r--r-- 1 root root 15 07-17 15:22 3
下面這個檔案的Change時間為2012-07-17:
[[email protected] ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 一般檔案
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-17 15:22:45.000000000 +0800我們改變一下它的許可權:
[[email protected] ~]# chmod 755 3
再來看看它的Change time:
[[email protected] ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 一般檔案
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-22 23:17:40.000000000 +0800再改一下它的使用者:
[[email protected] ~]# chown oracle.root 3
[[email protected] ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 一般檔案
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 500/ oracle) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-22 23:33:59.000000000 +0800再改變一下它的所屬組:
[[email protected] ~]# chgrp oinstall 3
[[email protected] ~]# ll
總計 4
-rwxr-xr-x 1 oracle oinstall 15 07-17 15:22 3
[[email protected] ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 一般檔案
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-22 23:36:14.000000000 +0800發現,只要是修改ls -l 裡面的任何資訊,那麼change time都會發生變化。
總結:find命令中的ctime並非是建立時間,而是檔案狀態改變時間。檔案的時間三屬性分別為access time,modify time和change time.
http://blog.itpub.net/26675752/viewspace-1058878/
linux下find命令-atime,-ctime,-mtime真正含義