在linux系統中,檔案是時間戳屬性有三個
- Access
- Modify
- Change
這三個可以通過
stat
指令來檢視
相應的,find指令中有三個參數atime mtime ctime分别呢對應着Access、Modify、Change 配合着相應的參數,可以用來查找相應時間範圍内的檔案,按照文檔解釋
簡名 | 全名 | 中文名 | 含義 |
---|---|---|---|
atime | access time | 通路時間 | 檔案中的資料庫最後被通路的時間 |
mtime | modify time | 修改時間 | 檔案内容被修改的最後時間 |
ctime | change time | 變化時間 | 檔案的中繼資料發生變化。 |
什麼樣的操作會影響這三個時間,這個就是比較模糊的。為了搞清楚,先來做一些操作來驗證一下。
建立一個檔案
touch timestamp
然後來檢視一下這個檔案的三個時間戳
$ stat timestamp
File: `timestamp'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:50:53.000000000 +0800
Change: 2019-05-18 16:50:53.000000000 +0800
以下就是驗證操作:
- echo指令
echo 'test' >> timestamp
File: `timestamp'
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:50:59.000000000 +0800
Change: 2019-05-18 16:50:59.000000000 +0800
可以看到 mtime與ctime都發生了改變,但是atime沒有變化
- vim
使用vim在做操作
vim timestamp
File: `timestamp'
Size: 7 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
同樣的 mtime與ctime都發生了改變,但是atime沒有變化
-
ls more less cp cat
再用ls指令檢視一下
ls timestamp
timestamp
$ stat timestamp
File: `timestamp'
Size: 7 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
$ cat timestamp
testaa
$ stat timestamp
File: `timestamp'
Size: 7 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
$ more timestamp
testaa
$ stat timestamp
File: `timestamp'
Size: 7 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
- chmod chown
$ chmod 777 timestamp
$ stat timestamp
File: `timestamp'
Size: 7 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 802838 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:56:31.000000000 +0800