Transferred from: http://www.cnblogs.com/perfy/archive/2012/07/23/2605550.html
Abbreviated version:
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 > fileParameters:
-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 >> textfile3Put
Test. txt file thrown into the trash, empty value 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>
options
-a,-- Show-all equivalent to-VET
-E equivalent to-VE
-t and-VT equivalent
-v,--show-nonprinting use ^ and M-references, except LFD and tab
--HELP displays this help message and leaves the
1.1 Cat View File content instance;
De>[[email protected] ~]# cat/etc/profile Note: View the content of the profile file under the/etc/directory;
[Email protected] ~]# cat-b/etc/fstab Note: View the profile content in the/etc/directory, and number the non-blank lines, starting with the line number 1;
[Email protected] ~]# cat-n/etc/profile Note: The numbering of all rows (including blank lines) of the profile in/etc directory is displayed;
[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 content for the file; Note: This is for the Linuxsir.org.txt file input content;
> North-South Testing; Note: This is for the Linuxsir.org.txt file input content;
> EOF Note: Exit Edit status;
[email protected] ~]# cat Linuxsir.org.txt Note: We take a 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 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;
A detailed description of CAT commands under Linux
A detailed description of CAT commands under Linux