Cat is a more common command in Linux, but are you really familiar with its usage?
There are three major features of cat:
1. Display the entire file at once. $ cat FileName
2. Create a file from the keyboard. $ cat > FileName
Only new files can be created and existing files cannot be edited.
3. Merge several files into one file: $cat file1 file2 > file
Parameters:
-N or--number the number of rows for all outputs starting from 1
-B or--number-nonblank and-n similar, except for blank lines not numbered
-S or--squeeze-blank when you encounter a blank line that has more than two consecutive lines, replace the blank line with one line
-V or--show-nonprinting example:
Add a line number to the Textfile1 file and enter the Textfile2 file.
Cat-n textfile1 > Textfile2
Append the contents of the Textfile1 and Textfile2 files to the textfile3 after adding the line number (blank line not added).
Cat-b textfile1 textfile2 >> textfile3 Throw the Test.txt file into the trash, empty value test.txt
Cat/dev/null >/etc/test.txt
1.0 CAT grammatical structure;
de>cat [Options] [File]...de>
Options
-A,--show-all equivalent to-vet
-B,--number-nonblank number of non-null output lines
-e equivalent to-ve
-E,--show-ends displays at the end of each line
-N,--number all line numbers for the output
-S,--squeeze-blank does not output multiple lines of blank lines
-T vs.-VT equivalence
-T,--show-tabs to display the jump character as ^i
-U (ignored)
-V,--show-nonprinting uses ^ and M-references, except LFD and TAB
--HELP Display this help message and leave
1.1 Cat View File content instance;
De>[[email protected] ~]# cat/etc/profile Note: View the contents of the profile under the/etc/directory;
[[email protected] ~]# cat-b/etc/fstab Note: View the contents of the/etc/directory, and number of non-blank lines, line numbers starting from 1;
[Email protected] ~]# cat-n/etc/profile Note: All rows (including blank lines) of profile in/etc directory are numbered output display;
[Email protected] ~]# CAT-E/etc/profile Note: View the profile content under/etc/and append the $ symbol at the end of each line;de>
Cat plus parameter-N and NL tools, file content output at the same time, each line will be preceded by a line number;
De>[[email protected] ~]# cat-n/etc/profile
[Email protected] ~]# nl/etc/profilede>
Cat can display the contents of multiple files at the same time, for example, we can display the contents of two files simultaneously on a cat command;
De>[[email protected] ~]# cat/etc/fstab/etc/profilede>
For files with great content, cat can be routed through the pipeline | To more tools, and then to a page-by-page view;
De>[[email protected] ~]# Cat/etc/fstab/etc/profile | Morede>
1.2 Cat's creation, connection file function instance;
Cat has the ability to create files, after creating the file, to end with EOF or stop;
De>[[email protected] ~]# cat > Linuxsir.org.txt << EOF Note: Create a linuxsir.org.txt file;
> I'll test the cat creation file and enter content for the file; Note: This is for the linuxsir.org.txt file input;
> North-South Test; Note: This is for the Linuxsir.org.txt file input content;
> EOF Note: Exit Edit status;
[email protected] ~]# Cat Linuxsir.org.txt Note: We look at the contents of the Linuxsir.org.txt file;
Let me test the cat creation file and enter the content for the file;
North South and North Test;de>
Cat also has the ability to append content to existing files;
De>[[email protected] ~]# cat Linuxsir.txt Note: View the existing file Linuxsir.txt content;
I am Beinannanbei from linuxsir.org. Note: The content line
I am writing a document for the cat command
[email protected] ~]# cat >> linuxsir.txt << EOF Note: We append content to the Linuxsir.txt file;
> I'll test the cat's ability to append content to the document; Note: This is the content of the recovery
> OK?
> ok~
> North South
> EOF Note: Exit with EOF;
[email protected] ~]# cat linuxsir.txt Note: Check the contents of the file to see if the recovery was successful.
I am Beinannanbei from linuxsir.org.
I am writing a document for the cat command
Let me test cat's ability to append content to a document;
Ok?
ok~
North South De>
Cat connects the contents of multiple files and outputs them to a new file;
Suppose we have sir01.txt, Sir02.tx and Sir03.txt, and the contents are as follows;
De>[[email protected] ~]# cat Sir01.txt
123456
I am testing
[email protected] ~]# cat Sir02.txt
56789
Beinan tested
[email protected] ~]# cat Sir03.txt
09876
Linuxsir.org testingde>
I want to connect the Sir01.txt, Sir02.txt, and sir03.txt three files through cat (that is, the contents of the three files together) and output to a new file sir04.txt.
Note: the principle is to connect the contents of three files, then create a sir04.txt file and write the contents of several files to Sir04.txt. In particular, if you enter an existing Sir04.txt file, the Sir04.txt content will be emptied.
De>[[email protected] ~]# cat sir01.txt sir02.txt sir03.txt > Sir04.txt
[Email protected] ~]# more Sir04.txt
123456
I am testing
56789
Beinan tested
09876
Linuxsir.org testingde>
Cat appends one or more existing file contents to an existing file
De>[[email protected] ~]# cat Sir00.txt
Linuxsir.org Forever
[email protected] ~]# cat sir01.txt sir02.txt sir03.txt >> sir00.txt
[email protected] ~]# cat Sir00.txt
Linuxsir.org Forever
123456
I am testing
56789
Beinan tested
09876
Linuxsir.org testingde>
Warning: We want to know that > means to create,>> is append. Don't get mixed up. It is not a joke to make a mistake;
Linux Cat detailed