In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use cat text output commands in Linux? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The cat command is a text output command under linux, which is usually used to view the contents of a file.
I. function
Cat has three main functions:
1. Displays the entire file at once.
The code is as follows:
$cat filename
two。 Create a file from the keyboard.
The code is as follows:
$cat > filename
Only new files can be created, existing files cannot be edited.
3. Merge several files into one file.
The code is as follows:
$cat file1 file2 > file
The specific cat command format is as follows:
The code is as follows:
Cat [- AbeEnstTuv] [--help] [--version] fileName
Description: connect the file string to the basic output (screen or add > fileName to another file)
Parameters:
-n or-number numbering all output lines starting with 1
-b or-number-nonblank is similar to-n, except that blank lines are not numbered
When-s or-squeeze-blank encounters blank lines with more than two consecutive lines, replace them with blank lines of one line
-v or-show-nonprinting
Example:
The code is as follows:
Cat-n linuxfile1 > linuxfile2
Add the line number to the linuxfile1 file and enter it into the linuxfile2 file.
The code is as follows:
Cat-b linuxfile1 linuxfile2 > > linuxfile3
Append the contents of linuxfile1 and linuxfile2 files to linuxfile3 after adding line numbers (blank lines are not added).
Example:
Add the line number to the linuxfile1 file and enter it into the linuxfile2 file.
The code is as follows:
Cat-n linuxfile1 > linuxfile2
Append the contents of linuxfile1 and linuxfile2 files to linuxfile3 after adding line numbers (blank lines are not added).
The code is as follows:
Cat-b linuxfile1 linuxfile2 > > linuxfile3
The code is as follows:
Cat / dev/null > / etc/test.txt
This is emptying / etc/test.txt file content
We often see something like cat sdkjflk in linux shell scripts.
> asdlfj
> HHH
The "HHH" here replaces the function of "EOF". The result is the same.
Quote
The code is as follows:
# cat iii.txt
Sdlkfjksl
Sdkjflk
Asdlfj
4. Non-scripting
If not in the script, we can use Ctrl-D to output the identity of the EOF
The code is as follows:
# cat > iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
Ctrl-D
Results:
Quote
The code is as follows:
# cat iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
IV. Demonstration of basic usage examples
Example 1
The code is as follows:
[root@localhost ~] # cat test # normal output
1111111111
2222222222
3333333333
[root@localhost ~] # cat-n test # begins with a line number
1 1111111111
two
three
4 2222222222
five
6 3333333333
[root@localhost ~] # cat-E test # ends with $
1111111111 $
$
$
2222222222 $
$
3333333333 $
[root@localhost ~] # cat-s test # more than two blank lines are merged into one
1111111111
2222222222
3333333333
[root@localhost ~] # cat-ns test # go to blank lines and add line numbers
1 1111111111
two
3 2222222222
four
5 3333333333
Example 2
The code is as follows:
[zhangy@BlackGhost awksed] $cat x * > google_bak.tar.gz # merge files
Example 3
The code is as follows:
# cat > aa # enter the content from the keyboard to the file, enter to save, and exit Ctrl+z
4234234
234234
^ Z
[4] + Stopped cat > aa
# cat file1 file2 > file # merge two files into one
Example 4
The code is as follows:
# cat test.tar.gz_?? > test.tar.gz # you can use the cat command to merge multiple compressed packages that are cut into one
# tar-xvzf test.tar.gz # and then extract it with the tar command
After reading the above, have you mastered how to use cat text output commands in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.