Cat commands in Linux

Source: Internet
Author: User

Simplified Version:

CAT has three main functions:

1. display the entire file at a time. $ 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 indicates the number of all output rows starting from 1.

-B or -- number-nonblank is similar to-N, but is not numbered for blank rows.

-S or -- Squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row

-V or -- show-nonprinting
Example:

Add the row number to the file content of textfile1 and enter textfile2.

Cat-N textfile1> textfile2

Add the row number to the file content of textfile1 and textfile2 (blank rows are not added) and then append the content to textfile3.

Cat-B textfile1 textfile2> textfile3
  Throw the test.txt file into the garbage box and leave the value test.txt empty.
CAT/dev/null>/etc/test.txt
     

Details:

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

Cat is a tool for viewing and connecting text files. View the content of a file. It is easy to use cat, that is, the file name is directly followed by CAT.

For example:

De> [root @ localhost ~] # Cat/etc/fstabde>

To make it easier for new students to master this tool flexibly, let's talk about common parameters;



1.0 cat syntax structure;

De> CAT [Option] [file] ...de>
Option
-A, -- show-all is equivalent to-vet.
-B, -- number-nonblank: Number of non-empty output rows
-E is equivalent to-ve.
-E, -- show-ends is displayed at the end of each line $
-N, -- number indicates the number of all rows output.
-S, -- Squeeze-blank does not output multiple empty rows
-T is equivalent to-vt.
-T, -- show-tabs: The jump character is displayed as ^ I
-U (ignored)
-V, -- show-nonprinting use ^ and M-reference, except LFD and Tab
-- Help: displays the help information and leaves



1.1 cat view the file content instance;

De> [root @ localhost ~] # Cat/etc/profile Note: view the profile file content in the/etc/directory;

[Root @ localhost ~] # Cat-B/etc/fstab Note: view the profile content in the/etc/directory and number non-blank rows. The row number starts from 1;

[Root @ localhost ~] # Cat-N/etc/profile Note: Numbers all the rows (including blank rows) of the profile in the/etc directory are output;

[Root @ localhost ~] # Cat-E/etc/profile Note: view the profile content under/etc/and add the $ symbol at the end of each line. De>

The cat parameter-N is similar to the NL tool. When the file content is output, the row number is added before each line;

De> [root @ localhost ~] # Cat-N/etc/profile

[Root @ localhost ~] # NL/etc/profilede>

Cat can display the content of multiple files at the same time. For example, we can display the content of two files at the same time on a cat command;

De> [root @ localhost ~] # Cat/etc/fstab/etc/profilede>

For files with large content, cat can be transferred to the more tool through pipelines and viewed on a page by page;

De> [root @ localhost ~] # Cat/etc/fstab/etc/profile | morede>



1.2 create and connect cat file function instances;



Cat can create files. After creating a file, it must end with EOF or stop;

De> [root @ localhost ~] # Cat> linuxsir.org.txt <EOF Note: Create the linuxsir.org.txt file;

> I will test cat to create a file and input content for the file. Note: This is the input content for the linuxsir.org.txt file;

> North-south-north testing; note: this is the input content of linuxsir.org.txt;

> EOF Note: exit the editing status;


[Root @ localhost ~] # Cat linuxsir.org.txt Note: We recommend the content of the linuxsir.org.txt file;


I will test cat to create a file and input content for the file;

North-south-north testing; de>

CAT also provides the ability to Append content to existing files;

De> [root @ localhost ~] # Cat linuxsir.txt Note: Check the existing file linuxsir.txt content;

I am beinannanbei from linuxsir. org. Note: Content line

I am writing a document for the cat command



[Root @ localhost ~] # Cat> linuxsir.txt <EOF Note: We Append content to the linuxsir.txt file;

> I will test the cat Append content to the document function. Note: This is the retrieved content.

> OK?

> OK ~

> Presented to the North South

> EOF Note: exit with EOF;



[Root @ localhost ~] # Cat linuxsir.txt Note: Check the file content to see if it has been recovered successfully.

I am beinannanbei from linuxsir. org.

I am writing a document for the cat command


Let me test the cat Append content to the document;

OK?

OK ~

North South presents de>




Cat connects the content of multiple files and outputs them to a new file;

Suppose we have sir01.txt1_sir02.txand sir03.txt, And the content is 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 use Cat to connect the three files sir01.txt1_sir02.txtand sir03.txt together (I also say that the three files are connected together and exported to a new file sir04.txt.

Note: logging is in progress. The special value is that if you input a sir04.txt file that already exists, the sir04.txt content will be cleared.

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 the content of one or more existing files 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: You Need To Know> Create,> append. Never confuse. Making mistakes is not a joke;

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.