Linux cat commands

Source: Internet
Author: User

Usage: CAT [-abeensttuv] [-- help] [-- version] filename
Note: connect the archive string and upload it to the Basic output (screen or add> filename to another archive)
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:
Cat-N textfile1> textfile2: add the row number to the file content of textfile1 and enter textfile2.
Cat-B textfile1 textfile2> textfile3 adds the file content of textfile1 and textfile2 to the row number (blank rows are not added) and then attaches the content to textfile3.
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
CAT/dev/null>/etc/test.txt this indicates clearing the/etc/test.txt File Content
Cat can also be used to create an image file. For example, if you want to create an image file for a soft disk, place the soft disk and press
CAT/dev/fd0> OUTFILE
If you want to write the image file to a soft disk
Cat img_file>/dev/fd0
Note:
1. OUTFILE indicates the name of the output image file.
2. img_file refers to image file.
3. If the device is written back from the image file, the device capacity must be equal to that of the device.
4. It is usually used to make boot CIDS.

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. $ 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:

Cat-N textfile1> textfile2: add the row number to the file content of textfile1 and enter textfile2.

Cat-B textfile1 textfile2> textfile3 adds the file content of textfile1 and textfile2 to the row number (blank rows are not added) and then attaches the content to textfile3.

Example:

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

Cat-N textfile1> textfile

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

CAT/dev/null>/etc/test.txt this indicates clearing the/etc/test.txt File Content

Cat can also be used to create an image file. For example, if you want to create an image file for a soft disk, place the soft disk and press

CAT/dev/fd0> OUTFILE
% W

If you want to write the image file to a soft disk

Cat img_file>/dev/fd0

Note:
& Copy; newboys -- newboys comprehensive forum

1. OUTFILE indicates the name of the output image file.

2. img_file refers to image file.

3. If the device is written back from the image file, the device capacity must be equal to that of the device.

4. It is usually used to make boot CIDS.

13.9. Use cat to operate files
Red Hat Linux has a tool program that helps you retain a short list, collect these lists, and even reveal your system information to you.
This tool is called Cat. It is short for concatenate, which means to merge files.
The cat command also displays the content of the entire file on the screen (for example, type cat filename.txt ). If the file is too long, it will quickly roll over the screen. To prevent this effect, run cat filename.txt | less.
The pipeline (|) and less commands are used together to display files one page at a time. Then, you can use the up or down arrow to move forward or backward in the page number. For more information about how to use pipelines to merge two different functions, see
Section 13.10


.
13.9.1. Use redirection
The redirection is to make shell change the standard output, or change the target of the standard output.
To redirect the standard output, use the> symbol. Put the> symbol after the cat command (or after any tool program or application written to the standard output), it will re-direct its output to the file following the symbol.
For example, CAT itself will output the content you entered on the screen, as if you were repeating the line you just typed. The following example shows that cat will repeat each line you enter:

Figure 13-5. Cat command

To redirect cat output to a file, enter the following command at the shell prompt (Press [enter] to bring you to a blank line ):
Cat> sneakers.txt

Figure 13-6. Redirect the output to a file

Press the [enter] key to go to an empty line, and then use the [CTRL]-[d] key to exit cat.
Notes
Figure 13-6


Is there a difference? It is not displayed again here. This is because the cat standard output has been reoriented. The redirection is a new file named sneakers.txt you just created.
When you run the cat command, you will find files in your directory
As shown in the preceding figure, you can use Cat to read files. At the prompt, type:
Cat sneakers.txt


Be careful

Exercise caution when redirecting the output to a file because it is easy to overwrite an existing file! Unless you want to replace this file, make sure that the file name you created is different from the existing file name.
The output is redirected to another file, which is also called home.txt. In this example, type the command cat> home.txt, and then press [enter], followed:
Bring the Coffee Home

Take off shoes

Put on sneakers

Make some coffee

Relax!

Now, on an empty line, use the [CTRL]-[d] key combination to exit cat.
Next, use Cat to connect home.txt and sneakers.txt, and then redirect the output of the two files to a new file named saturday.txt.
Figure 13-7


). Type the following command:
Cat sneakers.txt home.txt> saturday.txt


Figure 13-7. Connection file and redirection output

You can see that cat has added home.txt to the end of sneakers.txt.
13.9.2. standard output after completion
You can use output redirection to add new information after an existing file. This is similar to the> symbol used by you. You are telling shell to send the information to a place other than the standard output.
However, when you use>, you are adding information to the file, rather than Completely replacing the file content.
The best way to explain this is to demonstrate the instance to you. We can use the two files (sneakers.txt and home.txt) that have just been created, and then use the post-completion output symbol to connect them. To add the information of home.txt to the information of sneakers.txt, enter:
Cat home.txt> sneakers.txt
Now, run the cat sneakers.txt command to check. The final output shows the content of home.txt at the end of the file:
Buy some sneakers
Then go to the coffee shop
Then buy some coffee
Bring the Coffee Home
Take off shoes
Put on sneakers
Make some coffee
Relax!
The command you typed fills in the output of the file home.txt to the file sneakers.txt.
After completing the output, you can use existing files instead of creating new files, saving yourself some time (and some disk clusters ).
Now, compare the results of the sneakers.txt file and the saturday.txt file, and you will see that they are exactly the same. To make a comparison, type:
Cat sneakers.txt; CAT saturday.txt
The content of both files will be displayed-first, the sneakers.txt file, and then the saturday.txt file (such
Figure 13-8


).

Figure 13-8. concatenate commands and comparison files

13.9.3. Redirection standard input
You can not only redirect to the standard output, but also to the standard input.
When you use a heavily oriented standard input symbol
Cat
The cat command reads the output of sneakers.txt, which is used to separate the cat command and file.

Figure 13-9. Redirection standard input

This article is from the chinaunix blog. If you want to view the original text, click:
Http://blog.chinaunix.net/u1/53051/showart_424003.html

Related Article

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.