Cat commands in Linux are commonly used to connect files or standard input and print, or to stitch together several files in standard input and print, often in conjunction with redirection symbols.
Command format
Cat [option] ... [File] ...
Command function
Show entire file contents at once: Cat filename
Create a file from the keyboard: Cat > NewFile, can only create new files to use, cannot edit existing files
Combine several files into one file: Cat file1 file2 > File3
Command parameters
-A or--show-all equivalent to-vet
-B or--number-nonblank number of non-null output lines
-e equivalent to-ve
-e shows $ at the end of each line
-N or--number numbering of all output lines
-S or--squeeze-blank encounters more than two rows of contiguous empty rows, turning these empty lines into a blank row
-T equivalent to-VT
-U is ignored
-V or--show-nonprinting use ^ and M-references, except LFD and TAB
Example: 1. viewing file content Instances
[[email protected] ~]# cat ett.txt #查看ett. txt [[email protected] ~]# cat-b ett.txt #查看ett. txt content, numbering non-empty lines, starting with 1 [email Protected] ~]# cat-n ett.txt #查看ett. txt content, numbering all lines, starting with 1 [[email protected] ~]# cat-e ett.txt #查看ett. txt content, adding a $[at the end of each line when output [email protected] ~]# cat ett.txt a.txt #同时查看ett. txt and a.txt content. [email protected] ~]# Cat Install.log Install.log.syslog | More #查看大文件时通过管道符使用more可以进行分页显示.
2. Create and connect file instances
[[email protected] ~]# cat > Readme.txt hahahahjdwkjhashdlinuxoldboy# Press Ctrl+d to exit save [email protected] ~]############## #######################[[email protected] ~]# cat > Readme.txt<
[[email protected] ~]# cat a.txt b.txt c.txt >d.txt #合并a, b, c file contents, input to d.txt[[email protected] ~]# cat a.txt b.txt c.txt >> e.txt contents of #合并a, B, c files, append to E.txt
We know that ">" and ">>" are all data flow redirection operations, but > overwriting,>> during operation is an append, and the actual operation needs to generate a new file ">" and ">>" can be implemented, However, only the append can only use ">>", ">" Use caution, such as the existing configuration file using ">" will be the existing configuration empty, if there is no backup is troublesome.
One Linux command per day-cat