3.cat

0.簡述

cat命令可用于在屏幕上顯示文本文件,同時(shí)還可以合并文件

1.查看cat命令類型

[root@centos6 ~]# type cat
cat is /bin/cat

2.獲取幫助

[root@centos6 ~]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and 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.
  cat        Copy standard input to standard output.

3.常用功能展示
3.1 -E,-n,-b

[root@centos6 ~]# cat test.txt 
a
b
c    d
[root@centos6 ~]# cat -E test.txt   -E顯示行結(jié)束符$
a$
b$
c    d$
[root@centos6 ~]# cat -n test.txt   -n對(duì)顯示出的每一行進(jìn)行編號(hào)
1   a
2   b
3   c    d
[root@centos6 ~]# cat -n test.txt 
 1  a       
 2  b
 3  
 4   
 5  c    d
[root@centos6 ~]# cat -b test.txt   -b對(duì)顯示的非空行進(jìn)行編號(hào)
 1  a       
 2  b

 3   
 4  c    d

3.2 -A

[root@centos6 ~]# cat -E test.txt 
a       $
b$
c    d$
[root@centos6 ~]# cat -A test.txt   -A相當(dāng)于-vET,還可以顯示TAB
a^I^I$
b$
c    d$

3.3 -s

[root@centos6 ~]# cat test.txt 
a       


b


c    d
[root@centos6 ~]# cat -b test.txt 
1   a       


2   b


3   c    d
[root@centos6 ~]# cat -n test.txt 
1   a       
2   
3   
4   b
5   
6   
7   c    d
[root@centos6 ~]# cat -ns test.txt  -s選項(xiàng)將多個(gè)空行壓縮為一行
1   a       
2   
3   b
4   
5   c    d

4.tac命令

與cat命令相反,將文本倒序顯示
[root@centos6 ~]# cat test.txt 
a       
b
c    d
[root@centos6 ~]# tac test.txt 
c    d
b
a

5.nl命令

相當(dāng)于cat -b只對(duì)顯示文本的非空行進(jìn)行編號(hào)
[root@centos6 ~]# cat test.txt 
a       
b

c    d
[root@centos6 ~]# cat -b test.txt 
1   a       
2   b

3   c    d
[root@centos6 ~]# nl test.txt 
1   a       
2   b
   
3   c    d

6.rev

[root@centos6 ~]# cat test.txt 
abc
123
[root@centos6 ~]# rev test.txt  將同一行顯示文本倒序顯示,行的次序不變
cba
321
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容