Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the cat command in Linux

Shulou Source: shulou.com Published: 2022-05-31 12:35:00 09月28日 Update

This article introduces the relevant knowledge of "how to use the cat command in Linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. operating environment

Win10 64-bit operating system + CentOS7+MobaX

Second, the definition of Linux cat command

The cat (English spelling: concatenate) command is used to connect files and print to standard output devices.

III. Usage

Cat [options]... [file].

Output [file] or standard input combination to standard output.

IV. Common parameters

-n or-- number: number the number of lines of all output starting with 1.

-b or-- number-nonblank: similar to-n, except that blank lines are not numbered.

-s or-- squeeze-blank: when you encounter a blank line of more than two consecutive lines, replace it with a blank line of one line.

-v or-- show-nonprinting: use ^ and M-symbols, except for LFD and TAB.

-E or-- show-ends: displays $at the end of each line.

-T or-- show-tabs: displays the TAB character as ^ |.

-An or-- show-all: equivalent to-vET.

-e: equivalent to the "- vE" option.

-t: equivalent to the "- vT" option.

5. Demonstration

5.1 preconditions

1. Start the virtual machine and connect to the MobaX

two。 Create two files of any content (not in the topic of this article. Please refer to Linux to create files in the directory) as shown in the following figure (test11 and test22 files will be modified according to the needs of the example in the following example):

5.2 Instanc

1. View the contents of the test11 file.

Cat test11

two。 View the contents of the test11 file and add a line number (the number starts at 1).

Cat-n test11 or cat-- number

3. View the contents of the test22 file and number the non-white space (numbering starts with 1).

Cat-b test22 or cat-- number-nonblank

4. View the contents of the test22 file and replace more than two consecutive blank lines with one blank line.

Cat-s test22 or cat-- squeeze-blank or nl test22

5. View the contents of the test22 file and append the $symbol at the end.

Cat-E test22

6.cat can view multiple files at the same time

Cat test11 test22

7. For large files, you can use the pipe character (|) and more to view page by page (under the more command, use the space bar to turn the page down and N key to turn the page up)

Cat test11 | more

8. Write two files together to a new file (pay attention! If the written file has the original content, the original content will be emptied! )

Cat test11 test22 > test33

9. Append two files together to the new file (the original content will not be emptied)

Cat test11 > > test33

Never confuse > with > >! Using it incorrectly will bring great loss!

This is the end of the content of "how to use cat commands in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: File content blank command two blank line output original instance standard equivalent one line situation more knowledge symbol process large similar learned Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB Linux Redmi Shulou Information