Cat has three main functions: 1. Display the entire file at once. $ cat filename 2. Create a file from the keyboard. $ cat > FileName can only create new files and cannot edit existing files. 3. Merge several files into one file: $cat file1 file2 > file parameter:-N or--number starting from 1 for all output lines number-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 a line-V or--show-nonprinting example: Add the Textfile1 file to the line number and enter textfile2 this file cat-n te Xtfile1 > Textfile2 Append the contents of the Textfile1 and Textfile2 files to the textfile3 after adding the line number (blank lines not added). Cat-b textfile1 textfile2 >> textfile3
Test. txt files thrown into the trash, empty values test.txt cat/dev/null >/etc/test.txt
Detailed point of:
Ext.: http://blog.sina.com.cn/s/blog_52f6ead0010127xm.html
Cat is a text file viewing and linking tool. To view the contents of a file, it is simpler to use cat, which is the name of the cat directly behind it.
Like what:
De>[[email protected] ~]# cat/etc/fstabde>
In order to facilitate the novice brother to grasp the tool flexibly, we say a little more commonly used parameters;
1.0 CAT grammatical structure;
de>cat [Options] [File]...de>
option -A,--show-all equivalent to-vet-b,--number-nonblank to non-null output line number-e equivalent to-VE-E,--show-ends shows $-N at the end of each line,--number on output All line numbers-S,--squeeze-blank does not output multiple lines of empty lines-T and-VT equivalent-T,--show-tabs will be displayed as ^i-u (ignored)-V,--show-nonprinting using ^ and M-reference, in addition to Outside of 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 profile content in the/etc/directory, and the number of non-blank lines, line number starting from 1; [[email protected] ~]# cat-n/etc/profile Note: All rows of profile in/etc directory ( Include blank lines) for 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 the file Note: This is for linuxsir.org.txt file input; > north-South Test; Note: This is for linuxsir.org.txt file input; > EOF Note: Exit Edit status;
[email protected] ~]# Cat Linuxsir.org.txt Note: We look at the contents of the Linuxsir.org.txt file;
I'll test the cat to create the file and enter content for the file; North-South 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: 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 a document; Note: this is recovery content > 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 the 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 testi Ngde>
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;
A detailed description of CAT commands under Linux