A detailed description of CAT commands under Linux

Source: Internet
Author: User

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 > file parameter:
-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

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
-B,--number-nonblank number of non-null output lines
-e equivalent to-ve
-E,--show-ends displays at the end of each line
-N,--number all line numbers for the output
-S,--squeeze-blank does not output multiple lines of blank lines
-T vs.-VT equivalence
-T,--show-tabs to display the jump character as ^i
-U (ignored)
-V,--show-nonprinting uses ^ and M-references, except 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 contents of the/etc/directory, and number of non-blank lines, line numbers starting from 1;
[Email protected] ~]# cat-n/etc/profile Note: All rows (including blank lines) of profile in/etc directory are 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 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;

A detailed description of CAT commands under Linux

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.