Linux 日誌檢視 cat 命令

2021-10-23 11:16:59 字數 2863 閱讀 1143

cat命令的用途是連線檔案或標準輸入並列印。這個命令常用來顯示檔案內容,或者將幾個檔案連線起來顯示,或者從標準輸入讀取內容並顯示,它常與重定向符號配合使用。

cat主要有三大功能:

一次顯示整個檔案:cat filename;

將幾個檔案合併為乙個檔案:cat file1 file2 > file。

name(名稱)

cat - concatenate files and print on the standard output

連線多個檔案並在標準輸出裝置上顯示

synopsis(概要,大綱)

cat[option]

... [file]

...description(描述)

concatenate file(s), or standard input, to standard output.

連線多個檔案或標準輸入,顯示在標準輸出裝置上

-a, --show-all

equivalent to -vet

相當於 -vet

-b, --number-nonblank

number nonempty output lines, overrides -n

和 -n 相似,只不過對於空白行不編號。

-e equivalent to -ve

相當於 -ve

-e, --show-ends

display $ at end of each line

在每行結束處顯示 $。

-n, --number

number all output lines

由 1 開始對所有輸出的行數編號。

-s, --squeeze-blank

suppress repeated empty output lines

當遇到有連續兩行以上的空白行,就代換為一行的空白行。

-t equivalent to -vt

相當於 -vt

-t, --show-tabs

display tab characters as ^i

以 ^i 的方式顯示tab characters

-u (ignored)

-v, --show-nonprinting

use ^ and m- notation, except for lfd and tab

使用 ^ and m- 符號顯示非列印的字元,除了 lfd 和 tab

--help display this help and exit

顯示幫助資訊並退出

--version

output version information and exit

顯示版本資訊並退出

with no file, or when file is -, read standard input.

如果沒有指定檔案,或者檔案為-,那麼就從標準輸入上讀取。

examples(例子)

cat f - g

output f's contents, then standard input, then g's contents.

輸出 f 的內容,然後輸出標準輸入,然後輸出 g 的內容

cat copy standard input to standard output.

輸出標準輸入到標準輸出

1、把 test.log 的文件內容加上行號後輸入 test3.log 這個文件裡:

[root@peipei3514 usr]

# cat -b test.log > test3.log

2、把 test.log 和 test2.log 的文件內容加上行號(空白行不加)之後將內容附加到 test3.log 文件裡:

[root@peipei3514 usr]

# cat -b test.log test2.log > test3.log

3、清空 /etc/test.txt 文件內容:

[root@peipei3514 usr]

# cat /dev/null > /etc/test.log

4、連線兩個檔案並進行顯示:

[root@peipei3514 usr]

# cat test.log test2.log

...195 2018-09-12 15:53:16:724 uxtip

196 2018-09-13 15:54:06:724 xxtyn

197 2018-09-14 15:55:12:725 kwuax

198 2018-09-15 15:56:10:725 therp

199 2018-09-16 15:57:16:725 dwmtj

200 2018-09-17 15:58:13:725 phkiz

201 2018-09-18 18:50:25:778 zhwkd

202 2018-09-19 18:51:26:778 vqgrp

203 2018-09-20 18:52:37:779 uzdce

204 2018-09-21 18:53:40:779 ncish

205 2018-09-22 18:54:34:779 zcjuy

206 2018-09-23 18:55:38:779 sejkz

...

tac是將cat反寫過來,所以他的功能就跟 cat 相反, cat 是由第一行到最後一行連續顯示在螢幕上,而 tac 則是由最後一行到第一行反向在螢幕上顯示出來!

出自:

Linux日誌檢視之cat 命令使用介紹

cat命令的用途是連線檔案或標準輸入並列印。這個命令常用來顯示檔案內容,或者將幾個檔案連線起來顯示,或者從標準輸入讀取內容並顯示,它常與重定向符號配合使用。cat主要有三大功能 一次顯示整個檔案 cat filename 從鍵盤建立乙個檔案 cat filename 只能建立新檔案,不能編輯已有檔案...

Linux檢視日誌命令

1 cat命令 功能 1 顯示整個檔案。示例 cat filename 2 把檔案串連線後傳到基本輸出,如將幾個檔案合併為乙個檔案或輸出到螢幕。示例 cat file1 file2 file 說明 把檔案串連線後傳到基本輸出 螢幕或加 filename 到另乙個檔案 cat引數詳解 n 或 numb...

Linux檢視日誌命令

1 cat命令 功能 1 顯示整個檔案。示例 cat filename 2 把檔案串連線後傳到基本輸出,如將幾個檔案合併為乙個檔案或輸出到螢幕。示例 cat file1 file2 file 說明 把檔案串連線後傳到基本輸出 螢幕或加 filename 到另乙個檔案 cat引數詳解 n 或 numb...