国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

linux中查看和修改文件時(shí)間的命令

2024-08-27 23:58:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

linux下文件時(shí)間主要有下面三種:

1.1 modification time(mtime)

文件修改時(shí)間,即文件內(nèi)容的修改時(shí),更新這個(gè)時(shí)間,不包括文件權(quán)限和屬性的修改,使用ls -l查看,默認(rèn)顯示時(shí)間為mtime.

  1. $ ls -l uconv.h 
  2. -rw-rw-r--  1 work work 1808 Jul 23  2013 uconv.h 
  3. 1.2 status time(ctime) 

文件狀態(tài)status的修改時(shí)間,如文件的權(quán)限和屬性修改時(shí)更新這個(gè)時(shí)間,使用 ls --time=ctime 查看.

  1. $ ls -l --time=ctime uconv.h  
  2. -rw-rw-r--  1 work work 1808 Jul 23  2013 uconv.h 

1、stat查看文件時(shí)間

  1. [root@web10 ~]# stat install.log 
  2.   File: “install.log” 
  3.   Size: 33386           Blocks: 80         IO Block: 4096   一般文件 
  4. Device: fd00h/64768d    Inode: 7692962     Links: 1 
  5. Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root) 
  6. Access: 2012-07-13 16:02:34.000000000 +0800 
  7. Modify: 2011-11-29 16:03:06.000000000 +0800 
  8. Change: 2011-11-29 16:03:08.000000000 +0800 

說(shuō)明:Access訪(fǎng)問(wèn)時(shí)間,Modify修改時(shí)間,Change狀態(tài)改變時(shí)間,可以stat *查看這個(gè)目錄所有文件的狀態(tài),而我們想要查看某文件的三個(gè)時(shí)間中的具體某個(gè)時(shí)間,并以年月日時(shí)分秒的格式保存,我們可以使用下面的命令:

  1. [root@web10 ~]# stat install.log|grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}' 
  2. 20111129160306 --Vevb.com 
  3. 1.3 access time(atime) 

文件訪(fǎng)問(wèn)時(shí)間,當(dāng)文件內(nèi)容被獲取時(shí),更新這個(gè)時(shí)間,使用 ls --time=actime 查看.

$ ls -l --time=atime uconv.h

-rw-rw-r--  1 work work 1808 Dec 12  2013 uconv.h

相應(yīng)的通過(guò)ls 查看時(shí)也有三個(gè)時(shí)間:

• modification time(mtime,修改時(shí)間):當(dāng)該文件的“內(nèi)容數(shù)據(jù)”更改時(shí),就會(huì)更新這個(gè)時(shí)間。內(nèi)容數(shù)據(jù)指的是文件的內(nèi)容,而不是文件的屬性。

• status time(ctime,狀態(tài)時(shí)間):當(dāng)該文件的”狀態(tài)(status)”改變時(shí),就會(huì)更新這個(gè)時(shí)間,舉例來(lái)說(shuō),更改了權(quán)限與屬性,就會(huì)更新這個(gè)時(shí)間。

• access time(atime,存取時(shí)間):當(dāng)“取用文件內(nèi)容”時(shí),就會(huì)更新這個(gè)讀取時(shí)間。舉例來(lái)說(shuō),使用cat去讀取 ~/.bashrc,就會(huì)更新atime了。

  1. [root@web10 ~]# ls -l --time=ctime install.log 
  2. -rw-r--r-- 1 root root 33386 2011-11-29 install.log 
  3. [root@web10 ~]# ls -l --time=atime install.log 
  4. -rw-r--r-- 1 root root 33386 07-13 16:02 install.log 

注意:ls參數(shù)里沒(méi)有--mtime這個(gè)參數(shù),因?yàn)槲覀兡J(rèn)通過(guò)ls -l查看到的時(shí)間就是mtime 。

2.修改文件的時(shí)間

如果需要修改上述三個(gè)時(shí)間,使用touch命令來(lái)修改,touch filename,如果文件不存在,則新建一個(gè)文件.

  1. $ touch --help 
  2. Usage: touch [OPTION]... FILE... 
  3. Update the access and modification times of each FILE to the current time. 
  4.   -a                     change only the access time 
  5.                          修改訪(fǎng)問(wèn)時(shí)間 
  6.   -c, --no-create        do not create any files 
  7.                          修改文件三個(gè)時(shí)間,不存在則不創(chuàng)建 
  8.   -d, --date=STRING      parse STRING and use it instead of current time 
  9.                          指定時(shí)間代替當(dāng)前時(shí)間 
  10.   -f                     (ignored) 
  11.   -m                     change only the modification time 
  12.                          修改mtime 
  13.   -r, --reference=FILE   use this file's times instead of current time 
  14.   -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time 
  15.                          指定修改時(shí)間 

例如:

  1. $ touch -d "2 days ago" uconv.h 
  2. $ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ; 
  3. -rw-rw-r--  1 work work 1808 Jun 13 18:17 uconv.h 
  4. -rw-rw-r--  1 work work 1808 Jun 13 18:17 uconv.h 
  5. -rw-rw-r--  1 work work 1808 Jun 15 18:17 uconv.h 

將mtime和atime修改為兩天前,ctime沒(méi)變.

  1. $ touch -t 201406142020 uconv.h   
  2. $ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ; 
  3. -rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h 
  4. -rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h 
  5. -rw-rw-r--  1 work work 1808 Jun 15 18:23 uconv.h 

atime和mtime都變了,但是ctime變成了當(dāng)前時(shí)間,使用cp命令,-a保持原屬性.

  1. $ cp -a uconv.h uconv.h1 
  2. $ ll uconv.h1 ; ll --time=atime uconv.h1 ; ll --time=ctime uconv.h1 ; 
  3. -rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h1 
  4. -rw-rw-r--  1 work work 1808 Jun 15 18:25 uconv.h1 
  5. -rw-rw-r--  1 work work 1808 Jun 15 18:27 uconv.h1 

mtime和atime都保持原文件不變,但是ctime變成當(dāng)前時(shí)間.

注:如果touch后面接一個(gè)已經(jīng)存在的文件,則該文件的3個(gè)時(shí)間,atime/ctime/mtime,都會(huì)更新為當(dāng)前時(shí)間,若該文件不存在,則會(huì)主動(dòng)建立一個(gè)新的空文件.

  1. [root@web10 ~]# touch install.log 
  2. [root@web10 ~]# stat install.log 
  3.   File: “install.log” 
  4.   Size: 33386           Blocks: 80         IO Block: 4096   一般文件 
  5. Device: fd00h/64768d    Inode: 7692962     Links: 1 
  6. Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root) 
  7. Access: 2012-07-13 16:21:50.000000000 +0800 
  8. Modify: 2012-07-13 16:21:50.000000000 +0800 
  9. Change: 2012-07-13 16:21:50.000000000 +0800 

同樣,使用ls,查看到的結(jié)果也一樣.

  1. [root@web10 ~]# ls -l --time=ctime install.log 
  2. -rw-r--r-- 1 root root 33386 07-13 16:21 install.log 
  3. [root@web10 ~]# ls -l --time=atime install.log 
  4. -rw-r--r-- 1 root root 33386 07-13 16:21 install.log 
  5. [root@web10 ~]# ls -l install.log 
  6. -rw-r--r-- 1 root root 33386 07-13 16:21 install.log 

下面再看一個(gè)和touch不相關(guān)的例子:

  1. [root@web10 ~]# cp /etc/profile .;ll --time=atime profile ;ll --time=ctime profile 
  2.  
  3. cp:是否覆蓋“./profile”? y 
  4.  
  5. -rw-r--r-- 1 root root 1344 07-13 16:24 profile 
  6.  
  7. -rw-r--r-- 1 root root 1344 07-13 16:25 profile 

因?yàn)槲抑斑\(yùn)行過(guò)這個(gè)命令一次,所以會(huì)出現(xiàn)覆蓋,不過(guò)這個(gè)覆蓋出的好,剛才讓我們看到了atime和ctime的時(shí)間的差別.

我們?cè)倩氐絫ouch利用touch修改文件時(shí)間:

1.同時(shí)修改文件的修改時(shí)間和訪(fǎng)問(wèn)時(shí)間

touch -d "2010-05-31 08:10:30" install.log

2.只修改文件的修改時(shí)間

touch -m -d "2010-05-31 08:10:30" install.log

3.只修改文件的訪(fǎng)問(wèn)時(shí)間

touch -a -d "2010-05-31 08:10:30" install.log

下面再給一個(gè)rootkit木馬常用的伎倆,就是把后一個(gè)文件的時(shí)間修改成和前一個(gè)相同.

touch -acmr /bin/ls /etc/sh.conf

另外touch還支持像date命令一樣參數(shù)修改文件時(shí)間:

  1. [root@web10 ~]# touch -d "2 days ago" install.log ; ll install.log 
  2. -rw-r--r-- 1 root root 33386 07-11 16:35 install.log 

最后總結(jié)下常用的文件操作與時(shí)間的關(guān)系:

1、訪(fǎng)問(wèn)時(shí)間,讀一次這個(gè)文件的內(nèi)容,這個(gè)時(shí)間就會(huì)更新,比如對(duì)這個(gè)文件使用more命令,ls、stat命令都不會(huì)修改文件的訪(fǎng)問(wèn)時(shí)間.

2、修改時(shí)間,對(duì)文件內(nèi)容修改一次,這個(gè)時(shí)間就會(huì)更新,比如:vim后保存文件,ls -l列出的時(shí)間就是這個(gè)時(shí)間.

3、狀態(tài)改變時(shí)間,通過(guò)chmod命令更改一次文件屬性,這個(gè)時(shí)間就會(huì)更新,查看文件的詳細(xì)的狀態(tài)、準(zhǔn)確的修改時(shí)間等,可以通過(guò)stat命令 文件名.

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 重庆市| 修文县| 红桥区| 卢氏县| 石景山区| 乌兰察布市| 小金县| 渝北区| 兰考县| 嵩明县| 鄂托克旗| 双江| 绵阳市| 鄂温| 监利县| 成武县| 丰宁| 徐汇区| 龙口市| 霍林郭勒市| 青冈县| 上杭县| 昌宁县| 舞钢市| 葫芦岛市| 吉林省| 岱山县| 泉州市| 牡丹江市| 克什克腾旗| 黄梅县| 云霄县| 连云港市| 平潭县| 连江县| 岚皋县| 乌拉特中旗| 通化市| 华安县| 肇源县| 青铜峡市|