cat命令的用途是连接文件或标准输入并打印。这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用。
cat主要有三大功能:
一次显示整个文件:cat filename; 从键盘创建一个文件:cat > filename 只能创建新文件,不能编辑已有文件.; 将几个文件合并为一个文件:cat file1 file2 > file。
NAME(名称)
cat - concatenate files and print on the standard output
连接多个文件并在标准输出设备上显示
SYNOPSIS(概要,大纲)
cat [OPTION]... [FILE]...
DESCRIPTION(描述)
Concatenate FILE(s), or standard input, to standard output.
连接多个文件或标准输入,显示在标准输出设备上
-A, --show-all
equivalent to -vET
相当于 -vET
-b, --number-nonblank
number nonempty output lines, overrides -n
和 -n 相似,只不过对于空白行不编号。
-e equivalent to -vE
相当于 -vE
-E, --show-ends
display $ at end of each line
在每行结束处显示 $。
-n, --number
number all output lines
由 1 开始对所有输出的行数编号。
-s, --squeeze-blank
suppress repeated empty output lines
当遇到有连续两行以上的空白行,就代换为一行的空白行。
-t equivalent to -vT
相当于 -vT
-T, --show-tabs
display TAB characters as ^I
以 ^I 的方式显示TAB characters
-u (ignored)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
使用 ^ and M- 符号显示非打印的字符,除了 LFD 和 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.
输出 f 的内容,然后输出标准输入,然后输出 g 的内容
cat Copy standard input to standard output.
输出标准输入到标准输出
1、把 test.log 的文档内容加上行号后输入 test3.log 这个文档里:
[root@peipei3514 usr]# cat -b test.log > test3.log
2、把 test.log 和 test2.log 的文档内容加上行号(空白行不加)之后将内容附加到 test3.log 文档里:
[root@peipei3514 usr]# cat -b test.log test2.log > test3.log
3、清空 /etc/test.txt 文档内容:
[root@peipei3514 usr]# cat /dev/null > /etc/test.log
4、连接两个文件并进行显示:
[root@peipei3514 usr]# cat test.log test2.log
...
195 2018-09-12 15:53:16:724 UXTIP
196 2018-09-13 15:54:06:724 XXTYN
197 2018-09-14 15:55:12:725 KWUAX
198 2018-09-15 15:56:10:725 THERP
199 2018-09-16 15:57:16:725 DWMTJ
200 2018-09-17 15:58:13:725 PHKIZ
201 2018-09-18 18:50:25:778 ZHWKD
202 2018-09-19 18:51:26:778 VQGRP
203 2018-09-20 18:52:37:779 UZDCE
204 2018-09-21 18:53:40:779 NCISH
205 2018-09-22 18:54:34:779 ZCJUY
206 2018-09-23 18:55:38:779 SEJKZ
...
tac 是将 cat反写过来,所以他的功能就跟 cat 相反, cat 是由第一行到最后一行连续显示在萤幕上,而 tac 则是由最后一行到第一行反向在萤幕上显示出来!
希望与广大网友互动??
点此进行留言吧!