linux下touch命令修改文件時間戳

linuxtouch命令用來修改文件時間戳,或者新建一個不存在的文件linux

wKiom1c8AQbyRcOfAAA4lWtVNn4553.png上圖中,access、modify、change分別是訪問時間、修改時間、改變時間,即爲文件的時間戳。ide

1命令格式:spa

touch [選項]... 文件名...blog

2命令參數:文檔

-a   或--time=atime或--time=access或--time=use  只更改存取時間。get

-c   或--no-create  不創建任何文檔。it

-d  使用指定的日期時間,而非如今的時間。io

-f  此參數將忽略不予處理,僅負責解決BSD版本touch指令的兼容性問題。class

-m   或--time=mtime或--time=modify  只更改變更時間。test

-r  把指定文檔或目錄的日期時間,通通設成和參考文檔或目錄的日期時間相同。

-t  使用指定的日期時間,而非如今的時間。

3命令功能:

touch命令參數可更改文檔或目錄的日期時間,包括存取時間和更改時間。 

4使用範例:

實例一:建立不存在的文件

命令:

touch test1.txt test2.txt

輸出:

[root@localhost test]# touch test1.txt test2.txt

[root@localhost test]# ll

-rw-r--r--. 1root root 0 May 18 11:11 test1.txt

-rw-r--r--.1 root root 0 May 18 11:11 test2.txt

若是test3.txt不存在,則不建立文件

[root@localhost test]# touch -c test3.txt

[root@localhost test]# ll

-rw-r--r--. 1root root 0 May 18 11:11 test1.txt

-rw-r--r--.1 root root 0 May 18 11:11 test2.txt

實例二:更新test.txt的時間和test2.txt時間戳相同

命令:

touch -r test.txt test2.txt

輸出:

 [root@localhost test]# touch test.txt

[root@localhost test]# touch -r test.txt test2.txt

[root@localhost test]# ll

total 0

-rw-r--r--. 1 root root 0 May 18 11:11 test1.txt

-rw-r--r--. 1 root root 0 May 18 11:22 test2.txt

-rw-r--r--.1 root root 0 May 18 11:22 test.txt

實例三:設定文件的時間戳

命令:

touch -t 201605171210.20 test.txt

輸出:

[root@localhost test]# ll

-rw-r--r--. 1root root 0 May 18 11:11 test1.txt

-rw-r--r--.1 root root 0 May 18 11:22 test2.txt

-rw-r--r--. 1 root root 0 May 18 11:22 test.txt 

[root@localhost test]# touch -t 201605171210.20 test.txt

[root@localhost test]# ll

-rw-r--r--. 1 rootroot 0 May 18 11:11 test1.txt

-rw-r--r--.1 root root 0 May 18 11:22 test2.txt

-rw-r--r--.1 root root 0 May 17 12:10 test.txt

wKiom1c8AGyRIBV8AABFOXJqlUM509.png

說明:

-t  time 使用指定的時間值 time 做爲指定文件相應時間戳記的新值.此處的 time規定爲以下形式的十進制數:      

  [[CC]YY]MMDDhhmm[.SS]     

  這裏,CC爲年數中的前兩位,即」世紀數」;YY爲年數的後兩位,即某世紀中的年數.若是不給出CC的值,則touch   將把年數CCYY限定在1969--2068以內.MM爲月數,DD爲天將把年數CCYY限定在1969--2068以內.MM爲月數,DD爲天數,hh 爲小時數(幾點),mm爲分鐘數,SS爲秒數.此處秒的設定範圍是0--61,這樣能夠處理閏秒.這些數字組成的時間是環境變量TZ指定的時區中的一個時 間.因爲系統的限制,早於1970年1月1日的時間是錯誤的。

相關文章
相關標籤/搜索