touch命令開始看成了權(quán)限命令后來發(fā)現(xiàn)touch命令是對(duì)目錄或文件進(jìn)行時(shí)間日期的一個(gè)更新操作了,下面來看一些簡單的例子.
名稱:touch
使用權(quán)限:所有使用者
使用方式:
- touch [-acfm]
- [-r reference-file] [--file=reference-file]
- [-t MMDDhhmm[[CC]YY][.ss]]
- [-d time] [--date=time] [--time={atime,access,use,mtime,modify}]
- [--no-create] [--help] [--version]
- file1 [file2 ...]
說明:touch 指令改變檔案的時(shí)間記錄,ls -l 可以顯示檔案的時(shí)間記錄.
參數(shù):
- a 改變檔案的讀取時(shí)間記錄。
- m 改變檔案的修改時(shí)間記錄。
- c 假如目的檔案不存在,不會(huì)建立新的檔案。與 --no-create 的效果一樣。
- f 不使用,是為了與其他 unix 系統(tǒng)的相容性而保留。
- r 使用參考檔的時(shí)間記錄,與 --file 的效果一樣。
- d 設(shè)定時(shí)間與日期,可以使用各種不同的格式。
- t 設(shè)定檔案的時(shí)間記錄,格式與 date 指令相同。
- --no-create 不會(huì)建立新檔案。
- --help 列出指令格式。
- --version 列出版本訊息。
使用范例:
實(shí)例一:創(chuàng)建不存在的文件
命令:touch log2012.log log2013.log
輸出:
- [root@localhost test]# touch log2012.log log2013.log
- [root@localhost test]# ll //Vevb.com
- -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)建文件.
- [root@localhost test]# touch -c log2014.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
實(shí)例二:更新log.log的時(shí)間和log2012.log時(shí)間戳相同.
命令:touch -r log.log log2012.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
- -rw-r--r-- 1 root root 0 10-28 14:48 log.log
- [root@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í)例三:設(shè)定文件的時(shí)間戳
命令:touch -t 201211142234.50 log.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
- [root@localhost test]# touch -t 201211142234.50 log.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 2012-11-14 log.log
說明:-t time 使用指定的時(shí)間值 time 作為指定文件相應(yīng)時(shí)間戳記的新值,此處的 time規(guī)定為如下形式的十進(jìn)制數(shù):
[[CC]YY]MMDDhhmm[.SS]
這里,CC為年數(shù)中的前兩位,即”世紀(jì)數(shù)”;YY為年數(shù)的后兩位,即某世紀(jì)中的年數(shù),如果不給出CC的值,則touch 將把年數(shù)CCYY限定在1969--2068之內(nèi).MM為月數(shù),DD為天將把年數(shù)CCYY限定在1969--2068之內(nèi),MM為月數(shù),DD為天數(shù),hh 為小時(shí)數(shù)(幾點(diǎn)),mm為分鐘數(shù),SS為秒數(shù),此處秒的設(shè)定范圍是0--61,這樣可以處理閏秒,這些數(shù)字組成的時(shí)間是環(huán)境變量TZ指定的時(shí)區(qū)中的一個(gè)時(shí) 間,由于系統(tǒng)的限制,早于1970年1月1日的時(shí)間是錯(cuò)誤的.
新聞熱點(diǎn)
疑難解答
圖片精選