天天看點

獨幕喜劇Linux檔案時間

獨幕喜劇Linux檔案時間

在Linux相關崗位的面試中,經常會問到文檔時間的問題。Linux文檔的時間一般分三種:Access time-atime(通路時間)、Modification time-mtime(内容修改時間)、status-ctime(狀态時間)

mtime可以通過ls -l指令顯示,表示文檔内容最後被修改的時間。

atime可以通過ls -lu指令顯示,表示文檔最後被通路的時間。

ctime可以通過ls -lc指令顯示,表示文檔屬性最後被修改的時間。

示例說明,以下示例均已Ubuntu 10.04.4為操作平台:

----------------------------------------------------------------------------

Jacob@server01:~/test$ date                                 #顯示目前時間為09:29 

Tue Dec  4 09:29:35 CST 2012 

Jacob@server01:~/test$ touch test.txt                       #建立空白檔案test.txt 

Jacob@server01:~/test$ ls -l                                #檢視檔案mtime為09:29 

-rw-r--r-- 1 Jacob Jacob 0 2012-12-04 09:29 test.txt 

Jacob@server01:~/test$ ls -lu                               #檢視檔案atime為09:29 

Jacob@server01:~/test$ ls -lc                               #檢視檔案ctime為09:29 

說明:檔案被常見是所有時間均為建立檔案的初始時間。

Jacob@server01:~/test$ date                                 #檢視目前時間為09:31 

Tue Dec  4 09:31:10 CST 2012 

Jacob@server01:~/test$ echo "abc" > test.txt                #修改檔案内容為abc 

Jacob@server01:~/test$ ls -l                                #檢視檔案mtime為09:31 

-rw-r--r-- 1 Jacob Jacob 0 2012-12-04 09:31 test.txt 

Jacob@server01:~/test$ ls -lc                               #檢視檔案ctime為09:31,檔案内容修改的同時,檔案屬性發生了變化 

-rw-r--r-- 1 Jacob Jacob    4 2012-12-04 09:31 test.txt 

Jacob@server01:~/test$ ls -lu 

-rw-r--r-- 1 Jacob Jacob    4 2012-12-04 09:29 test.txt      #檢視檔案atime為09:29 

Jacob@server01:~/test$ date                                 #檢視目前時間為09:33 

Tue Dec  4 09:33:44 CST 2012 

Jacob@server01:~/test$ chmod a+x test.txt                   #修改檔案屬性 

Jacob@server01:~/test$ ls -l 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:31 test.txt        #檢視檔案mtime為09:31 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:29 test.txt        #檢視檔案atime為09:29 

Jacob@server01:~/test$ ls -lc 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:33 test.txt        #檢視檔案ctime為90:33 

-----------------------------------------------------------------------------

Jacob@server01:~/test$ date                                 #檢視目前時間為90:35 

Tue Dec  4 09:35:03 CST 2012 

Jacob@server01:~/test$ cat test.txt                         #檢視通路檔案内容 

abc 

Jacob@server01:~/test$ ls -l                                #檢視檔案mtime為09:31 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:31 test.txt 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:35 test.txt        #檢視檔案atime為09:35 

-rwxr-xr-x 1 Jacob Jacob 4 2012-12-04 09:33 test.txt        #檢視檔案ctime為09:33 

本文轉自丁丁曆險51CTO部落格,原文連結:http://blog.51cto./manual/1077971 ,如需轉載請自行聯系原作者

繼續閱讀