Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of cat Command under linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the usage of cat command under linux". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of cat command under linux".

1. Command format:

Cat [options] [files]...

2. Command function:

Cat has three main functions:

1. Show the entire file at once: cat filename

two。 Create a file from the keyboard: cat > filename can only create new files, not edit existing files.

3. Merge several files into one file: cat file1 file2 > file

3. Command parameters:

-A,-- show-all is equivalent to-vET

-b,-- number-nonblank to the non-empty outgoing line number

-e is equivalent to-vE

-E,-- show-ends displays $at the end of each line

-n,-- number numbers all lines of output, starting with 1, numbers all lines of output

-s,-- squeeze-blank has more than two blank lines in a row, so replace it with a blank line

-t is equivalent to-vT

-T,-- show-tabs displays tabbed characters as ^ I.

-u (ignored)

-v,-- show-nonprinting uses ^ and M-references, except for LFD and TAB

4. Use an example:

Example 1: enter the contents of the log2012.log file with a line number into the log2013.log file

Command:

Cat-n log2012.log log2013.log

Output:

The code is as follows:

[root@localhost test] # cat log2012.log

2012-01

2012-02

= [root@localhost test] # cat log2013.log

2013-01

2013-02

2013-03

= [root@localhost test] # cat-n log2012.log log2013.log

1 2012-01

2 2012-02

three

four

5 =

6 2013-01

7 2013-02

eight

nine

10 2013-03

11 = [root@localhost test] #

Description:

Example 2: append the contents of log2012.log and log2013.log files to log.log after adding line numbers (blank lines are not added).

Command:

Cat-b log2012.log log2013.log log.log

Output:

The code is as follows:

[root@localhost 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 = [root@localhost test] #

Example 3: enter the contents of the log2012.log file with a line number into the log.log file

Command:

Output:

The code is as follows:

[root@localhost test] # cat log.log

[root@localhost test] # cat-n log2012.log > log.log

[root@localhost test] # cat-n log.log

1 2012-01

2 2012-02

three

four

5 =

[root@localhost test] #

Example 4: use here doc to generate files

Output:

The code is as follows:

[root@localhost test] # cat > log.txt World

> Linux

> PWD=$ (pwd)

> EOF

[root@localhost test] # ls-l log.txt

-rw-r--r-- 1 root root 37 10-28 17:07 log.txt

[root@localhost test] # cat log.txt

Hello

World

Linux

PWD=/opt/soft/test

[root@localhost test] #

Description:

Note that in bold, here doc can do string substitution.

Note:

Tac (shown in reverse)

Command:

Tac log.txt

Output:

The code is as follows:

[root@localhost test] # tac log.txt

PWD=/opt/soft/test

Linux

World

Hello

Tac reverses cat, so its function is the opposite of cat. Cat is displayed continuously on the screen from the first line to the last line, while tac is displayed on the screen from the last line to the first line!

Thank you for reading, the above is the content of "the usage of cat command under linux". After the study of this article, I believe you have a deeper understanding of the usage of cat command under linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report