1. 命令解析
命令用途:
- 显示整个文件的内容;
- 创建一个新文件,并从键盘向文件输入内容;
- 将几个文件的内容合并到一个新文件;
命令格式:
cat [OPTION]... FILE...
命令参数:
-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 显示文件内容
[root@test catTest]# cat f1
Hello
This
is
My
Password=${pwd}
2.2 创建一个新文件,使用here doc的方式录入内容
[root@test catTest]# cat <<EOF > f3
> This
> is
> f3
> EOF
[root@test catTest]# cat f3
This
is
f3
2.3 显示文件内容并标出行号,包括空行 -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 显示文件内容并标出行号,不包括空行 -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 在显示每行的结尾时附加$ -E
[root@test catTest]# cat -ET f4
this is f1\n$
This$
is$
f3$
$
$
After blank is$
new line$
$