In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to use the cat command in the linux system, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
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:
Copy the code
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:
Copy the code
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:
Copy the code
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:
Copy the code
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:
Copy the code
The code is as follows:
[root@localhost test] # tac log.txt
PWD=/opt/soft/test
Linux
World
Hello
After reading the above, do you have any further understanding of how the cat command is used in the linux system? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.