日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux cat指令(用于连接文件并打印到标准输出设备上)

發布時間:2025/3/20 linux 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

注:

  • OUTFILE 指輸出的鏡像文件名。
  • IMG_FILE 指鏡像文件。
  • 若從鏡像文件寫回 device 時,device 容量需與相當。
  • 通常用制作開機磁片。
  • (這個倒沒測試。。。)

    參考文章:Linux cat 命令

    總結

    以上是生活随笔為你收集整理的Linux cat指令(用于连接文件并打印到标准输出设备上)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。