How to use the cat command in Linux in ten minutes

WBOY
Release: 2022-01-12 17:59:48
forward
4828 people have browsed it

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.

How to use the cat command in Linux in ten minutes

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 [选项]... [文件]...
Copy after login

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):

How to use the cat command in Linux in ten minutesHow to use the cat command in Linux in ten minutes

How to use the cat command in Linux in ten minutes

##5.2 Example

1. View the contents of the test11 file.

cat test11
Copy after login

How to use the cat command in Linux in ten minutes

2. View the contents of the test11 file and add the line number (the number starts from 1).

cat -n test11 或 cat --number
Copy after login

How to use the cat command in Linux in ten minutes

3. View the contents of the test22 file and number the non-blank files (numbering starts from 1).

cat -b test22 或 cat --number-nonblank
Copy after login

How to use the cat command in Linux in ten minutes

4. 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 test22
Copy after login

How to use the cat command in Linux in ten minutes

How to use the cat command in Linux in ten minutes

5. View the content of the test22 file and append the $ sign at the end.

cat -E test22
Copy after login

How to use the cat command in Linux in ten minutes

6.cat can view multiple files at the same time

cat test11 test22
Copy after login

How to use the cat command in Linux in ten minutes

7. 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 | more
Copy after login

How to use the cat command in Linux in ten minutes

8. 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 > test33
Copy after login

How to use the cat command in Linux in ten minutes

How to use the cat command in Linux in ten minutes

9. Combine the two files and append them to the new file (the original content will not be cleared)

cat test11 >>test33
Copy after login

How to use the cat command in Linux in ten minutes

Never 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!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template