linux文件的mtime,ctime,atime

Linux文件與目錄的三種時間狀態
1.      mtime(medify time):最後一次修改文件或目錄的時間
2.      ctime(chang time) :最後一次改變文件或目錄(改變的是原數據即:屬性)的時間
:記錄該文件的inode節點被修改的時間。touch命令除了-d-t選項外都會改變該時間。而且chmod,chown等命令也能改變該值。
3.      atime(access time)::最後一次訪問文件或目錄的時間
 
對於文件:
    當修改mtime時,ctime必須隨着改變.因爲文件大小等都屬性;
有人說說atime也一定會改變,要想修改文件必須先訪問;其實是不對的
不必訪問文件就能修改其內容:如:#echo “This is a test !” >> /etc/issue,
issue文件內容會變,但並沒有訪問文件,所以atime並沒有改變.
 
對於目錄:
     訪問一個目錄其atime改變,mtime ,ctime不變;修改一個目錄:
在一個目錄下touch一個文件,
mtime與ctime會改變,atime不一定會變;
:[root@station16 ~]# stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
fevice: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:15:57.000000000 +0800
change: 2010-07-09 09:15:57.000000000 +0800
[root@station16 ~]# cd /tmp
[root@station16 tmp]# touch text.txt
[root@station16 tmp]# cd
[root@station16 ~]# !s
stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]#
 
atime改變,mtime ,ctime不變情況:
 
[root@station16 ~]# stat /tmp
  File: `/tmp'
  Size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]# cd /tmp
[root@station16 tmp]# ls
aa  text  text.txt
[root@station16 tmp]# cd
[root@station16 ~]# !s
stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:35:49.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]#
 
 
 
 
使用stat命令可以查看三時間值:如 stat filename
 
 
也可使用:
        ls -l file : 查看文件修改時間
       
ls -lc file: 查看文件狀態改動時間
       
ls -lu file: 查看文件訪問時間
 
 
touch命令[options]選項的時間格式[[CC]YY]MMDDhhmm[.ss]說明:
 
 

CC表示世紀

YY
表示年
MM
表示月
DD
表示日
hh
表示小時
mm
表示分鐘
ss
表示秒
201001311200.34
CCYYMMDDhhmm ss
表示時間爲201013112034
options :
      -t:後面可接時間,其格式如上所述
      -a:僅修改access time
      -c:僅修改時間,而不建立文件
      -m:僅修改mtime
例如:將issue文件日期改爲2008/07/15 13:13
 [root@station16 ~]# ls -l /etc/issue
-rw-r--r-- 1 root root 80 Jul  8 09:03 /etc/issue
[root@station16 ~]# touch -t 0807151313 /etc/issue
[root@station16 ~]# !l
ls -l /etc/issue
-rw-r--r-- 1 root root 80 Jul 15  2008 /etc/issue
[root@station16 ~]# stat /etc/issue
  File: `/etc/issue'
  Size: 80              Blocks: 16         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 3014852     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2008-07-15 13:13:00.000000000 +0800
Modify: 2008-07-15 13:13:00.000000000 +0800
Change: 2010-07-09 09:51:46.000000000 +0800
注意到我們改變了issuemtimeatime,並沒有改變ctime
 此時的ctime記錄的是當前時間。
 

本文出自 “linuxme” 博客,請務必保留此出處http://linuxme.blog.51cto.com/1850814/347549


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章