Linux cat指令
指令:cat
cat 指令用于連接配接檔案并列印到标準輸出裝置上。
使用權限
所有使用者
文法格式
cat [-AbeEnstTuv] [--help] [--version] fileName
[root@testhost]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version output version information and exit
With no FILE, or when FILE is -, read standard input.
Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
參數說明:
-n 或 --number:由 1 開始對所有輸出的行數編号。
-b 或 --number-nonblank:和 -n 相似,隻不過對于空白行不編号。
-s 或 --squeeze-blank:當遇到有連續兩行以上的空白行,就代換為一行的空白行。
-v 或 --show-nonprinting:使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外。
-E 或 --show-ends : 在每行結束處顯示 $。
-T 或 --show-tabs: 将 TAB 字元顯示為 ^I。
-e : 等價于 -vE。
-A, --show-all:等價于 -vET。
-e:等價于"-vE"選項;
-t:等價于"-vT"選項;
執行個體
把 textfile1 的文檔内容加上行号後輸入 testfile2 這個文檔裡:
[lzy@CentOS72Demo ~]$ cat testfile1 > testfile2
把 testfile1 和 testfile2 的文檔内容加上行号(空白行不加)之後将内容附加到 testfile3 文檔裡:
[lzy@CentOS72Demo ~]$ cat -b testfile1 testfile2 >> testfile3
清空 /etc/test 文檔内容:
[lzy@CentOS72Demo ~]$ cat /dev/null > testfile
cat 也可以用來制作鏡像檔案。例如要制作軟碟的鏡像檔案,将軟碟放好後輸入:
cat /dev/fd0 > OUTFILE
相反的,如果想把 image file 寫到軟碟,輸入:
cat IMG_FILE > /dev/fd0
注:
- 1. OUTFILE 指輸出的鏡像檔案名。
- 2. IMG_FILE 指鏡像檔案。
- 3. 若從鏡像檔案寫回 device 時,device 容量需與相當。
- 4. 通常用制作開機磁片。
- 5. 通常/dev/null看作"黑洞". 它非常等價于一個隻寫檔案. 所有寫入它的内容都會永遠丢失. 而嘗試從它那兒讀取内容則什麼也讀不到. 然而, /dev/null對指令行和腳本都非常的有用.
***********************************************************
學習永遠不晚。——高爾基