The purpose of the cat command is to connect files or standard input and print. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols.
1. Command format:
Cat [Options] [file] ...
2. Command function:
Brother Even Linux training
Small, to talk about the three main features of cat:
1. Display the entire file at once: Cat filename
2. Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.
3. Merge several files into one file: Cat file1 file2 > file
3. Command parameters:
-A,--show-all equivalent to-vet
-B,--number-nonblank number of non-null output lines
-e equivalent to-ve
-E,--show-ends displays at the end of each line
-N,--number all line numbers for the output, numbering the number of rows for all outputs starting from 1
-S,--squeeze-blank a blank line that has more than two lines in a row and is substituted for a row
-T vs.-VT equivalence
-T,--show-tabs to display the ^i character as a
-U (ignored)
-V,--show-nonprinting uses ^ and M-references, except LFD and TAB
4. Usage examples:
Example one: Add the Log2012.log file contents to the line number and enter Log2013.log this file
Command:
Cat-n Log2012.loglog2013.log
Output:
Copy Code
The code is as follows:
[Email protected] test]# Catlog2012.log
2012-01
2012-02</p><p>======[[email protected] test]# cat Log2013.log
2013-01
2013-02</p><p>2013-03
======[[email protected]]# cat-n Log2012.log log2013.log
1 2012-01
2 2012-02
3
4
5 ======
6 2013-01
7 2013-02
8
9
10 2013-03
======[[email protected]]#
Description
Example two: Add the contents of the Log2012.log and Log2013.log files to the log.log after adding the line number (blank line).
Command:
Cat-b Log2012.loglog2013.log Log.log
Output:
Copy Code
The code is as follows:
[Email protected] test]# cat-b log2012.log log2013.log log.log
1 2012-01
2 2012-02
3 ======
4 2013-01
5 2013-02
6 2013-03
7 ======[[email protected]]#
Example three: Add the Log2012.log file contents to the line number after the input log.log this file
Command:
Output:
Copy Code
The code is as follows:
[Email protected] test]# Catlog.log
[Email protected] test]# cat-n log2012.log > Log.log
[Email protected] test]# cat-n log.log
1 2012-01
2 2012-02
3
4
5 ======
[Email protected] test]#
Example four: Using here doc to generate files
Output:
Copy Code
The code is as follows:
[Email protected] test]# Cat>log.txt <<eof
> Hello
> World
> Linux
> pwd=$ (PWD)
> EOF
[Email protected] test]# Ls-l Log.txt
-rw-r--r--1 root root 3710-28 17:07 log.txt
[Email protected] test]# Catlog.txt
Hello
World
Linux
Pwd=/opt/soft/test
[Email protected] test]#
Description
Note that the Bold section, here Doc, can be used for string substitution.
Note:
TAC (Reverse list)
Command:
TAC Log.txt
Output:
Copy Code
The code is as follows:
[Email protected] test]# Taclog.txt
Pwd=/opt/soft/test
Linux
World
Hello
The TAC is writing cat back, so his function is in contrast to cat, which is displayed continuously on the screen from the first line to the last line, while the TAC is displayed on the screen in reverse from the last line to the first line!
Linux Basic Tutorial Linux under the Cat command use detailed