Cat usage summary and cat usage Summary
1. view files
In LINUX, everything is a file. It is not enough for us to see the file name and directory name. Today, we will introduce the command cat for opening files. Of course, cat cannot be used for binary executable files.
In CentOS7, the/etc/profile file is used as an example, as follows:
First, how can I open this file? Run: cat/etc/passwd.
Can we see the row number for so many rows?
Cat-n/etc/passwd
-N: number
Obviously, empty rows are also marked in order. So how can we not Mark empty rows but only rows with content?
Cat-B/etc/profile
-B: number-nonblank
If multiple rows are empty, can they be compressed into one empty row?
Cat-sb/etc/profile
-S: squeeze-blank
However, the cat command cannot eliminate all blank lines.
Some unprintable characters are not displayed in the cat command. If you need to know, the displayed command is as follows:
Cat-An/etc/profile
-A: show-all is equivalent to-vET.
-E, -- show-ends: $ is displayed at the end of each line, and a line break is displayed.
-T, -- show-tabs: The jump character is displayed as ^ I
Common cat options for viewing files are:
Cat-nAb/etc/profile
2. Create a file
Cat can view the file content or create a file.
For example, create an aaa.txt file with the following content:
Cat> aaa.txt <EOF
> This is txt
>
> Sucess
> EOF
The Aaa.txt file has been created and can be viewed as follows:
Input: cat aaa.txt
If aaa.txt already exists, you need to append the content to this file, instead of overwriting the original content of the file. Use cat> aaa.txt <EOF
> Where is not first line
>
> Yes
> Sucess
> EOF
Explanation: After cat,> (Append content to the file, the original file exists) or> (create a new file). EOF can also be changed to other uppercase letters, but must correspond to each other.
3. Merge files
What should I do if I want to put two files into one?
For example, the above/etc/profileand aaa.txt files are displayed on the screen:
Cat aaa.txt/etc/profile
Therefore, you can use redirection to output the two files to a new file.
Cat aaa.txt/etc/profile> bbb.txt
Cat bbb.txt