In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use Linux cat command". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Linux cat command" can help you solve the problem.
How to create a file using cat
To create a file using the cat command, enter the following in the terminal window:
[linuxmi@linux:~/www.linuxmi.com] $cat > linuxmi.txt
When you create a file in this way, the cursor remains on the new line and you can start typing. This technique provides a good way to start text files. To finish editing the file, press Ctrl + D. The file will be saved as the file name you use.
Test whether the process is valid by typing the following command:
[linuxmi@linux:~/www.linuxmi.com] $ls-lt
You should see the new file and the size should be greater than 0.
How to use cat to display files
C when the file is large, the text flashes quickly on the screen (scrolling), and the user often cannot see what is displayed clearly. Therefore, it is generally displayed on different screens with commands such as more. In order to control scrolling, press Ctrl+ S key to stop scrolling; press Ctrl+ Q key to resume scrolling. Press the Ctrl+C key to terminate the execution of the command and return to the Shell prompt status.
The at command also displays a file on the screen. All you need to do is delete the greater than sign, as shown below:
[linuxmi@linux:~/www.linuxmi.com] $cat linuxmi.txt
To view the file page by page, use the more command:
[linuxmi@linux:~/www.linuxmi.com] $cat linuxmi.com.py | more
Alternatively, you can use the less command:
[linuxmi@linux:~/www.linuxmi.com] $cat linuxmi.com.py | less
How to display line numbers
For all non-blank lines in the file, use the following command:
[linuxmi@linux:~/www.linuxmi.com] $cat-b linuxmi.txt
If the line has no characters at all, it will not be numbered. To display the navigation of all lines, regardless of whether they are blank or not, type:
[linuxmi@linux:~/www.linuxmi.com] $cat-n linuxmi.txt
How to display the end of each line
Sometimes, programmers find problems when parsing data files because there are unexpected hidden characters at the end of the line, such as spaces. This error will prevent its parser from working properly.
To display dollars as end-of-line characters, enter the following command:
[linuxmi@linux:~/www.linuxmi.com] $cat-E linuxmi.txt
As an example, see the following text
Hello Worldlinuxmi.comlinuxidcdebianCentOS
When you run this command with the cat-E command, you will receive the following output:
Hello Worldlinuxidccentos$
Reduce blank lines
When you use the cat command to display the contents of a file, you may not want to see blank lines with continuous loads. Use the-s switch to compress all blank lines into a single blank line:
[linuxmi@linux:~/www.linuxmi.com] $cat-s linuxmi.txt
How to display labels
When you display files that use tab delimiters, you usually do not see these tabs.
The following command displays TAB characters as * * ^ Illustrated characters, which makes it easy to view them:
[linuxmi@linux:~/www.linuxmi.com] $cat-T linuxmi.txt
Concatenate multiple files
The focus of cat is concatenation. Use the following command to connect multiple files to the screen:
Cat linux.txt Ubuntu.txt
To concatenate files and create new files, use the following command:
Cat linux.txt ubuntu.txt > linuxmi.txt
Display files in reverse order
Use the following command to display files in reverse order:
[linuxmi@linux:~/www.linuxmi.com] $tac linuxmi.txt
Technically, this is not a cat command, it is a tac command, but actually performs the same operation in the opposite direction. It is the contents of the output file in reverse order, and the last line of the file is displayed on the first line.
So much for the introduction of "how to use the Linux cat command". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.