Home>Article>Operation and Maintenance> How to use the cat command in Linux in ten minutes
This article brings you knowledge about the cat command in Linux. The cat command is used to connect files and print to the standard output device. I hope it will be helpful to everyone.
1. Operating environment
Win10 64-bit operating system CentOS7 MobaX
2. Definition of Linux cat command
The cat (full English spelling: concatenate) command is used to connect files and print to the standard output device.
3. Usage
cat [选项]... [文件]...
Output the [file] or standard input combination to the standard output.
4. Commonly used parameters
-n or --number: start from 1 for all outputs row number.
-b or --number-nonblank: Similar to -n, except that blank lines are not numbered.
-s or --squeeze-blank: When encountering two or more consecutive blank lines, replace them with one blank line.
-v or --show-nonprinting: Use ^ and M-symbols except LFD and TAB.
-E or --show-ends: Display $ at the end of each line.
-T or --show-tabs: Display TAB characters as ^|.
-A or --show-all: Equivalent to -vET.
-e: Equivalent to the "-vE" option.
-t: Equivalent to the "-vT" option.
5. Demonstration
5.1 Prerequisites
1. Start the virtual machine and connect Go to MobaX
2. Create two files with arbitrary content (the creation process is not the subject of this article and will not be described in detail. You can refer to Linux to create files in the directory) as shown in the figure below (in the following examples, we will follow the example Modify the two files test11 and test22 if necessary):
##5.2 Example
1. View the contents of the test11 file.cat test112. View the contents of the test11 file and add the line number (the number starts from 1).
cat -n test11 或 cat --number3. View the contents of the test22 file and number the non-blank files (numbering starts from 1).
cat -b test22 或 cat --number-nonblank4. Check the contents of the test22 file and replace two or more consecutive blank lines with one blank line.
cat -s test22 或 cat --squeeze-blank 或 nl test225. View the content of the test22 file and append the $ sign at the end.
cat -E test226.cat can view multiple files at the same time
cat test11 test227. For files with large content, it can Use the pipe character (|) and more to view page by page (use the space bar to page down and N keys to page up under the more command)
cat test11 | more8. Combine the two files and write them into a new file (Note!: If the written file has original content, the original content will be cleared!)
cat test11 test22 > test339. Combine the two files and append them to the new file (the original content will not be cleared)
cat test11 >>test33Never replace > with > ;>Confusion! ! Improper use will cause great losses! ! Related recommendations: "
Linux Video Tutorial"
The above is the detailed content of How to use the cat command in Linux in ten minutes. For more information, please follow other related articles on the PHP Chinese website!