Linux日誌查看之cat 命令使用介紹,linuxcat

來源:互聯網
上載者:User

Linux日誌查看之cat 命令使用介紹,linuxcat

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

cat主要有三大功能:

一次顯示整個檔案:cat filename; 從鍵盤建立一個檔案: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 UXTIP196 2018-09-13 15:54:06:724 XXTYN197 2018-09-14 15:55:12:725 KWUAX198 2018-09-15 15:56:10:725 THERP199 2018-09-16 15:57:16:725 DWMTJ200 2018-09-17 15:58:13:725 PHKIZ201 2018-09-18 18:50:25:778 ZHWKD202 2018-09-19 18:51:26:778 VQGRP203 2018-09-20 18:52:37:779 UZDCE204 2018-09-21 18:53:40:779 NCISH205 2018-09-22 18:54:34:779 ZCJUY206 2018-09-23 18:55:38:779 SEJKZ...

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.