1. Cat access to the normal file name, will print the contents of the document to the screen;
2. cat > file, this can write to the file "files", and finally press Ctrl + D to end the input, the data you entered will be saved to a file.
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
Cases:
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
Test. txt file thrown into the trash, empty value test.txt
Cat/dev/null >/etc/test.txt
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>
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;
The Cat command for Linux