1. 命令解析
命令用途:
- 顯示整個(gè)文件的內(nèi)容;
- 創(chuàng)建一個(gè)新文件,并從鍵盤向文件輸入內(nèi)容;
- 將幾個(gè)文件的內(nèi)容合并到一個(gè)新文件;
命令格式:
cat [OPTION]... FILE...
命令參數(shù):
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-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
2. 示例
2.1 顯示文件內(nèi)容
[root@test catTest]# cat f1
Hello
This
is
My
Password=${pwd}
2.2 創(chuàng)建一個(gè)新文件,使用here doc的方式錄入內(nèi)容
[root@test catTest]# cat <<EOF > f3
> This
> is
> f3
> EOF
[root@test catTest]# cat f3
This
is
f3
2.3 顯示文件內(nèi)容并標(biāo)出行號,包括空行 -n
[root@test catTest]# cat -n f3
1 This
2 is
3 f3
4
5
6 After blank is
7 new line
8
2.4 顯示文件內(nèi)容并標(biāo)出行號,不包括空行 -b
root@test catTest]# cat -b f3
1 This
2 is
3 f3
4 After blank is
5 new line
2.5 合并文件
root@test catTest]# cat f1 f3 > f4
2.6 倒序輸出
[root@test catTest]# cat f3
This
is
f3
After blank is
new line
[root@test catTest]# tac f4
new line
After blank is
f3
is
This
this is f1\n
2.7 在顯示每行的結(jié)尾時(shí)附加$ -E
[root@test catTest]# cat -ET f4
this is f1\n$
This$
is$
f3$
$
$
After blank is$
new line$
$