The use of CAT commands under Linux __linux

Source: Internet
Author: User

Abbreviated version: Cat has three major functions:
1. Display the entire file at once. $ cat FileName
2. Create a file from the keyboard. $ cat > FileName
You can only create new files, and you cannot edit existing files.
3. Merge several files into one file: $cat file1 file2 > file parameters:
-N or--number the number of rows for all outputs starting with 1
-B or--number-nonblank and-n are similar, except for blank lines not numbered
-S or--squeeze-blank is substituted for a line of blank lines when a blank line with two consecutive lines is encountered
-V or--show-nonprinting
Cases:
Add the Textfile1 file to the file and enter the Textfile2.
Cat-n textfile1 > Textfile2
Append the contents of Textfile1 and Textfile2 to the textfile3 after adding the line number (blank line not added).
Cat-b textfile1 Textfile2 >> Textfile3 throws the test. txt file into the bin, assigning null values Test.txt
Cat/dev/null >/etc/test.txt

Detailed points:

Ext: http://blog.sina.com.cn/s/blog_52f6ead0010127xm.html

Cat is a text file view and Connection tool. Check the contents of a file, with cat is simpler, is the cat directly after the file name.

For example: De>[root@localhost ~]# cat/etc/fstabde>

In order to facilitate the novice brother to master this tool flexibly, we say a little more commonly used parameters;


1.0 CAT grammatical structure;
de>cat [Options] [File]...de>

Options
-A,--show-all is equivalent to-vet
-B,--number-nonblank to Non-null output line number-
e equivalent to-ve-
E,--show-ends displays $-N at the end of each line
,--number For all row numbers of the output-
s,--squeeze-blank does not output multiple lines of empty rows-
t and-vt equivalence-
T,--show-tabs displays the jump characters as ^i-
u (ignored)-
V,--show-n Onprinting use ^ and M-references, except LFD and TAB
--help Display this help information and leave


1.1 Cat to view file content instances;
De>[root@localhost ~]# cat/etc/profile Note: View the contents of profile in/etc/directory;
[Root@localhost ~]# cat-b/etc/fstab Note: Look at the profile content in the/etc/directory, and number the nonblank lines, starting from 1;
[Root@localhost ~]# cat-n/etc/profile Note: A numbered output display of all rows (including blank lines) of profile in the/ETC directory;
[Root@localhost ~]# 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 are similar, the file content output at the same time, will precede each line with line number; De>[root@localhost ~]# cat-n/etc/profile
[Root@localhost ~]# 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 at the same time on a cat command; De>[root@localhost ~]# cat/etc/fstab/etc/profilede>

Cat for the content of a large file, you can through the pipeline | To the more tools, and then a page to view; De>[root@localhost ~]# Cat/etc/fstab/etc/profile | Morede>


1.2 Cat's creation, connection file function example;


Cat has the ability to create files, after creating files, to end with EOF or stop;
de>[root@localhost ~]# cat >    linuxsir.org.txt   << eof    Note: Create Linuxsir.org.txt file;
> I'll test the cat to create the file and enter the contents for the file;          Note: This is the input for the linuxsir.org.txt file;
> North-South North Test;                      Note: This is for linuxsir.org.txt file input;
> eof     Note: Exit Edit status;

[Root@localhost ~]# Cat linuxsir.org.txt    NOTE: Let's look at the contents of the Linuxsir.org.txt file;

I'll test the cat to create the file and enter the contents for the file;
North-South south-north Test;de>

Cat also has the ability to append content to existing files; de>[root@localhost ~]# cat linuxsir.txt Note: View existing files linuxsir.txt content;
I am Beinannanbei from linuxsir.org. Note: Content line
I'm writing a document for the cat command.


[Root@localhost ~]# cat >> linuxsir.txt << EOF Note: We append content to linuxsir.txt file;
> I test cat's ability to append content to a document; Note: This is the recovered content
> OK.
> ok~
> North South
> EOF Note: with EOF exit;


[Root@localhost ~]# Cat linuxsir.txt Note: View the contents of the file to see if it was recovered successfully.
I am Beinannanbei from linuxsir.org.
I'm writing a document for the cat command.

I'll test the cat's ability to append content to the document;
Ok.
ok~
North and South present de>




Cat connects the contents of multiple files and outputs it to a new file;

Suppose we have sir01.txt, Sir02.tx and Sir03.txt, and the contents are as follows; De>[root@localhost ~]# Cat Sir01.txt
123456
I am testing

[Root@localhost ~]# Cat Sir02.txt
56789
Beinan tested

[Root@localhost ~]# Cat Sir03.txt
09876
Linuxsir.org testingde>

I want to connect Sir01.txt, Sir02.txt and sir03.txt three files with cat (that is, put the contents of all three files together) and output them to a new file sir04.txt.

Note: the principle is to connect the contents of three files, create sir04.txt files, and write the contents of several files into Sir04.txt. It is particularly worth mentioning that if you enter an existing Sir04.txt file, the Sir04.txt content will be emptied. De>[root@localhost ~]# cat sir01.txt sir02.txt sir03.txt > Sir04.txt

[Root@localhost ~]# 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>[root@localhost ~]# cat Sir00.txt
Linuxsir.org Forever

[Root@localhost ~]# cat sir01.txt sir02.txt sir03.txt >> sir00.txt

[Root@localhost ~]# Cat Sir00.txt
Linuxsir.org Forever
123456
I am testing
56789
Beinan tested
09876
Linuxsir.org testingde>

Warning: We want to know > means to create,>> is append. Don't get mixed up. It is not a joke to make mistakes;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.