3.cat

0.简述

cat命令可用于在屏幕上显示文本文件,同时还可以合并文件

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显示行结束符$
a$
b$
c    d$
[root@centos6 ~]# cat -n test.txt   -n对显示出的每一行进行编号
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对显示的非空行进行编号
 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相当于-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选项将多个空行压缩为一行
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命令

相当于cat -b只对显示文本的非空行进行编号
[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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容