溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux中touch命令的作用是什么

發(fā)布時間:2021-03-12 16:12:58 來源:億速云 閱讀:637 作者:Leah 欄目:系統(tǒng)運維

本篇文章為大家展示了Linux中touch命令的作用是什么,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

linux的touch命令不常用,一般在使用make的時候可能會用到,用來修改文件時間戳,或者新建一個不存在的文件。

  1.命令格式:

  touch [選項]。。。 文件。。。

  2.命令參數(shù):

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

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

  -d  使用指定的日期時間,而非現(xiàn)在的時間。

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

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

  -r  把指定文檔或目錄的日期時間,統(tǒng)統(tǒng)設(shè)成和參考文檔或目錄的日期時間相同。

  -t  使用指定的日期時間,而非現(xiàn)在的時間。

  3.命令功能:

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

  4.使用范例:

  實例一:創(chuàng)建不存在的文件

  命令:

  touch log2012.log log2013.log

  輸出:

 ?。踨oot@localhost test]# touch log2012.log log2013.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  如果log2014.log不存在,則不創(chuàng)建文件

 ?。踨oot@localhost test]# touch -c log2014.log

 ?。踨oot@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  實例二:更新log.log的時間和log2012.log時間戳相同

  命令:

  touch -r log.log log2012.log

  輸出:

 ?。踨oot@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

 ?。踨oot@localhost test]# touch -r log.log log2012.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  實例三:設(shè)定文件的時間戳

  命令:

  touch -t 201211142234.50 log.log

  輸出:

 ?。踨oot@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

 ?。踨oot@localhost test]# touch -t 201211142234.50 log.log

 ?。踨oot@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 2012-11-14 log.log

  說明:

  -t time 使用指定的時間值 time 作為指定文件相應(yīng)時間戳記的新值.此處的 time規(guī)定為如下形式的十進制數(shù):

 ?。郏跜C]YY]MMDDhhmm[.SS]

改的是指定日期時間而不是現(xiàn)在時間,你學(xué)會了嗎?

上述內(nèi)容就是Linux中touch命令的作用是什么,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI