cat主要有三大功能:
1.一次顯示整個檔案。$ cat filename
2.從鍵盤建立一個檔案。$ cat > filename
隻能建立新檔案,不能編輯已有檔案.
3.将幾個檔案合并為一個檔案: $cat file1 file2 > file 參數:
-n 或 --number 由 1 開始對所有輸出的行數編号
-b 或 --number-nonblank 和 -n 相似,隻不過對于空白行不編号
-s 或 --squeeze-blank 當遇到有連續兩行以上的空白行,就代換為一行的空白行
-v 或 --show-nonprinting
例:
把 textfile1 的檔案内容加上行号後輸入 textfile2 這個檔案裡
cat -n textfile1 > textfile2
把 textfile1 和 textfile2 的檔案内容加上行号(空白行不加)之後将内容附加到 textfile3 裡。
cat -b textfile1 textfile2 >> textfile3 把 test.txt檔案扔進垃圾箱,賦空值test.txt
cat /dev/null > /etc/test.txt
cat 一般是用來檢視文本檔案内容
touch可以建立一個空檔案,可以修改檔案的建立時間。比如:編譯時看到提示檔案的時間為将來的時間,可以使用touch指令來修改。
inux的touch指令不常用,一般在使用make的時候可能會用到,用來修改檔案時間戳,或者建立一個不存在的檔案。
1.指令格式:
touch [選項]... 檔案...
2.指令參數:
-a 或--time=atime或--time=access或--time=use 隻更改存取時間。
-c 或--no-create 不建立任何文檔。
-d 使用指定的日期時間,而非現在的時間。
-f 此參數将忽略不予處理,僅負責解決BSD版本touch指令的相容性問題。
-m 或--time=mtime或--time=modify 隻更改變動時間。
-r 把指定文檔或目錄的日期時間,統統設成和參考文檔或目錄的日期時間相同。
-t 使用指定的日期時間,而非現在的時間。
3.指令功能:
touch指令參數可更改文檔或目錄的日期時間,包括存取時間和更改時間。
4.使用範例:
執行個體一:建立不存在的檔案
指令:
touch log2012.log log2013.log
輸出:
[[email protected] test]# touch log2012.log log2013.log
[[email protected] 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不存在,則不建立檔案
[[email protected] test]# touch -c log2014.log
[[email protected] 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
輸出:
[[email protected] 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
[[email protected] test]# touch -r log.log log2012.log
[[email protected] 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
執行個體三:設定檔案的時間戳
指令:
touch -t 201211142234.50 log.log
輸出:
[[email protected] 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
[[email protected] test]# touch -t 201211142234.50 log.log
[[email protected] 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 作為指定檔案相應時間戳記的新值.此處的 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日的時間是錯誤的。