Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習 Linux

Linux cat 指令詳解:檢視與輸出檔案內容

cat 的兩個主要用途:把文字內容輸出到螢幕;把文字內容輸出到另一個檔案。

參數說明:

-n:為所有行編號;
-b:不為空白行編號;
-s:把連續多個空白行壓縮為一行。

原始檔案 1.txt 內容(含空白行):

[root@test tools]# cat 1.txt
   c
   d
   e

   f

   g

為所有行編號:

[root@test tools]# cat -n 1.txt
     1  c
     2
     3  d
     4  e
     5
     6
     7  f
     8
     9
    10
    11  g

只為非空白行編號:

[root@test tools]# cat -b 1.txt
     1  c
     2  d
     3  e
     4  f
     5  g

把連續空白行壓縮為一行:

[root@test tools]# cat -s 1.txt
c
d
e
f
g

輸出到另一個檔案並驗證:

[root@test tools]# cat 1.txt > 2.txt
[root@test tools]# cat 2.txt
   c
   d
   e

   f

   g
Copyright © Linux教程網 All Rights Reserved