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