LINUX

LINUX CAT指令

介紹

cat指令用來串接檔案並輸出到螢幕上。

語法

cat [options] [files]

常用的options

-T  Print tabs as ^|.

-E  Print newlines as $.

-v  Print other nonprinting characters in a human-readable format.

-n  Prepend line numbers to every line.

-b  Prepend line numbers to nonblank lines.

-s  Squeeze each sequence of blank lines into a single blank line.

範例

假設現在有兩個檔案:

file1.txt:
file1 header
file1 content
file1 footer
----------分隔線----------
file2.txt:
file2 header
file2 content
file2 footer

你可以串接這兩個檔案並輸出到螢幕上:

⤍ cat file1.txt file2.txt
file1 header
file1 content
file1 footer
file2 header
file2 content
file2 footer

如果只有一個檔案,相當於檢視這個檔案:

⤍ cat file1.txt
file1 header
file1 content
file1 footer

發佈留言