Linux cat指令(用于连接文件并打印到标准输出设备上)
生活随笔
收集整理的這篇文章主要介紹了
Linux cat指令(用于连接文件并打印到标准输出设备上)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cat(英文全拼:concatenate)命令用于連接文件并打印到標準輸出設備上。
文章目錄
- 使用權限
- 語法格式
- 參數說明
- 實例
- 把 textfile1 的文檔內容加上行號后輸入 textfile2 這個文檔里(-n)
- 把 textfile1 和 textfile2 的文檔內容加上行號(空白行不加)之后將內容附加到 textfile3 文檔里(-b)
- 清空 /etc/test.txt 文檔內容(cat /dev/null > [目標文件路徑])
- cat 也可以用來制作鏡像文件。例如要制作軟盤的鏡像文件,將軟盤放好后輸入
使用權限
所有使用者
語法格式
cat [-AbeEnstTuv] [--help] [--version] fileName參數說明
-n 或 --number:由 1 開始對所有輸出的行數編號。-b 或 --number-nonblank:和 -n 相似,只不過對于空白行不編號。-s 或 --squeeze-blank:當遇到有連續兩行以上的空白行,就代換為一行的空白行。-v 或 --show-nonprinting:使用 ^ 和 M- 符號,除了 LFD 和 TAB 之外。-E 或 --show-ends : 在每行結束處顯示 $。-T 或 --show-tabs: 將 TAB 字符顯示為 ^I。-A, --show-all:等價于 -vET。-e:等價于"-vE"選項;-t:等價于"-vT"選項;實例
把 textfile1 的文檔內容加上行號后輸入 textfile2 這個文檔里(-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 的文檔內容加上行號(空白行不加)之后將內容附加到 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 文檔內容(cat /dev/null > [目標文件路徑])
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 也可以用來制作鏡像文件。例如要制作軟盤的鏡像文件,將軟盤放好后輸入
cat /dev/fd0 > OUTFILE相反的,如果想把 image file 寫到軟盤,輸入:
cat IMG_FILE > /dev/fd0注:
(這個倒沒測試。。。)
參考文章:Linux cat 命令
總結
以上是生活随笔為你收集整理的Linux cat指令(用于连接文件并打印到标准输出设备上)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux shell #[感叹号]/b
- 下一篇: 正常shell bash脚本文件最后一行