Linux每天一個命令:cat
Linux cat命令
命令:cat
cat 命令用於連接文件並打印到標準輸出設備上。
使用權限
所有使用者
語法格式
cat [-AbeEnstTuv] [--help] [--version] fileName [[email protected]]# 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
-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 這個文檔裏:
[[email protected] ~]$ cat testfile1 > testfile2
把 testfile1 和 testfile2 的文檔內容加上行號(空白行不加)之後將內容附加到 testfile3 文檔裏:
[[email protected] ~]$ cat -b testfile1 testfile2 >> testfile3
清空 /etc/test 文檔內容:
[[email protected] ~]$ 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對命令行和腳本都非常的有用.
***********************************************************
學習永遠不晚。——高爾基
***********************************************************
Linux每天一個命令:cat