Linux cat指令(用于连接文件并打印到标准输出设备上)
生活随笔
收集整理的這篇文章主要介紹了
Linux cat指令(用于连接文件并打印到标准输出设备上)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
cat(英文全拼:concatenate)命令用于連接文件并打印到標(biāo)準(zhǔn)輸出設(shè)備上。
文章目錄
- 使用權(quán)限
- 語(yǔ)法格式
- 參數(shù)說(shuō)明
- 實(shí)例
- 把 textfile1 的文檔內(nèi)容加上行號(hào)后輸入 textfile2 這個(gè)文檔里(-n)
- 把 textfile1 和 textfile2 的文檔內(nèi)容加上行號(hào)(空白行不加)之后將內(nèi)容附加到 textfile3 文檔里(-b)
- 清空 /etc/test.txt 文檔內(nèi)容(cat /dev/null > [目標(biāo)文件路徑])
- cat 也可以用來(lái)制作鏡像文件。例如要制作軟盤的鏡像文件,將軟盤放好后輸入
使用權(quán)限
所有使用者
語(yǔ)法格式
cat [-AbeEnstTuv] [--help] [--version] fileName參數(shù)說(shuō)明
-n 或 --number:由 1 開(kāi)始對(duì)所有輸出的行數(shù)編號(hào)。-b 或 --number-nonblank:和 -n 相似,只不過(guò)對(duì)于空白行不編號(hào)。-s 或 --squeeze-blank:當(dāng)遇到有連續(xù)兩行以上的空白行,就代換為一行的空白行。-v 或 --show-nonprinting:使用 ^ 和 M- 符號(hào),除了 LFD 和 TAB 之外。-E 或 --show-ends : 在每行結(jié)束處顯示 $。-T 或 --show-tabs: 將 TAB 字符顯示為 ^I。-A, --show-all:等價(jià)于 -vET。-e:等價(jià)于"-vE"選項(xiàng);-t:等價(jià)于"-vT"選項(xiàng);實(shí)例
把 textfile1 的文檔內(nèi)容加上行號(hào)后輸入 textfile2 這個(gè)文檔里(-n)
cat -n textfile1 > textfile2 [root@T300v2:/userdata/TEST_BASH]# ls hello.sh [root@T300v2:/userdata/TEST_BASH]# cat hello.sh #!/bin/Bash #The first program # Author: shenchao (E-mail: shenchao@lampbrother.net) echo -e "Mr. Shen Chao is the most honest man in LampBrother" [root@T300v2:/userdata/TEST_BASH]# cat -n hello.sh > hello2.sh [root@T300v2:/userdata/TEST_BASH]# ls hello.sh hello2.sh [root@T300v2:/userdata/TEST_BASH]# cat hello2.sh 1 #!/bin/Bash 2 #The first program 3 # Author: shenchao (E-mail: shenchao@lampbrother.net) 4 echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@T300v2:/userdata/TEST_BASH]#把 textfile1 和 textfile2 的文檔內(nèi)容加上行號(hào)(空白行不加)之后將內(nèi)容附加到 textfile3 文檔里(-b)
cat -b textfile1 textfile2 >> textfile3 [root@T300v2:/userdata/TEST_BASH]# ls hello.sh hello2.sh [root@T300v2:/userdata/TEST_BASH]# cat hello.sh #!/bin/Bash #The first program # Author: shenchao (E-mail: shenchao@lampbrother.net) echo -e "Mr. Shen Chao is the most honest man in LampBrother" [root@T300v2:/userdata/TEST_BASH]# cat hello2.sh 1 #!/bin/Bash 2 #The first program 3 # Author: shenchao (E-mail: shenchao@lampbrother.net) 4 echo -e "Mr. Shen Chao is the most honest man in LampBrother" [root@T300v2:/userdata/TEST_BASH]# cat -b hello.sh hello2.sh >> hello3.sh [root@T300v2:/userdata/TEST_BASH]# cat hello3.sh 1 #!/bin/Bash 2 #The first program 3 # Author: shenchao (E-mail: shenchao@lampbrother.net) 4 echo -e "Mr. Shen Chao is the most honest man in LampBrother"5 1 #!/bin/Bash 6 2 #The first program 7 3 # Author: shenchao (E-mail: shenchao@lampbrother.net) 8 4 echo -e "Mr. Shen Chao is the most honest man in LampBrother"清空 /etc/test.txt 文檔內(nèi)容(cat /dev/null > [目標(biāo)文件路徑])
cat /dev/null > /etc/test.txt [root@T300v2:/userdata/TEST_BASH]# ls hello.sh hello2.sh hello3.sh [root@T300v2:/userdata/TEST_BASH]# cat hello.sh #!/bin/Bash #The first program # Author: shenchao (E-mail: shenchao@lampbrother.net) echo -e "Mr. Shen Chao is the most honest man in LampBrother" [root@T300v2:/userdata/TEST_BASH]# cat /dev/null > ./hello.sh [root@T300v2:/userdata/TEST_BASH]# cat hello.sh [root@T300v2:/userdata/TEST_BASH]#cat 也可以用來(lái)制作鏡像文件。例如要制作軟盤的鏡像文件,將軟盤放好后輸入
cat /dev/fd0 > OUTFILE相反的,如果想把 image file 寫到軟盤,輸入:
cat IMG_FILE > /dev/fd0注:
(這個(gè)倒沒(méi)測(cè)試。。。)
參考文章:Linux cat 命令
總結(jié)
以上是生活随笔為你收集整理的Linux cat指令(用于连接文件并打印到标准输出设备上)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux shell #[感叹号]/b
- 下一篇: 正常shell bash脚本文件最后一行