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.
Cat commands connect files and print to standard output devices, which cat often uses to display the contents of a file, similar to the type command below. Note: When the file is large, the text flashes quickly on the screen (scrolling), and the user is often not aware of what is displayed. Therefore, generally with more commands split screen display. in order to control the scrolling screen, you can press the Ctrl+s key, stop the scrolling screen, press the CTRL+Q key to restore the scroll screen. Press the CTRL + C (break) key to terminate the execution of the command and return to the shell prompt state.
1. Command format:
Cat [Options] [file] ...
2. Command function:
There are three major 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 content to the line number, and then print Log2013.log this file
Command:
Cat-n Log2012.log Log2013.log
Output:
[email protected] test]# cat Log2012.log
2012-01
2012-02
======[[email protected] test]# cat Log2013.log
2013-01
2013-02
2013-03
======[[email protected] test]# 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] test]#
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.log log2013.log> Log.log
Output:
[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] test]#
Example three: Add the Log2012.log file contents to the line number after the input log.log this file
Command:
Output:
[email protected] test]# cat Log.log
[Email protected] test]# cat-n log2012.log > Log.log
[Email protected] test]# cat-n log.log
1 1 Gao Cat file
2 2finish
3 3exit
4 4
5 5
6 6:wq
7 7
8 8\t Tab
[Email protected] test]#
Example four: Using here doc to generate files
Output:
[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 notoginseng 10-28 17:07 log.txt
[email protected] test]# Cat Log.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:
[Email protected] test]# TAC Log.txt
Pwd=/opt/soft/test
Linux
World
Hello
Description
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!
I often use the cat command:
Cat-n fileName: 1 starts numbering all output lines;
Cat-b FileName: Similar to-N, except that the blank line is not numbered;
Cat-s FileName: When encountering two consecutive lines above the blank line, the substitution is a row of blank lines;
Cat fileName1 fileName2: Print the contents of two files in a row.
Cat is used with other grep, regular expressions.
-A: Displays non-printable characters with "$" at the end of the line;
-E: Equivalent to "-ve" option;
-T: equivalent to the "-vt" option;
Linux Learning Note 9--command cat