A detailed description of how to use the Linux Cat command-connect the file string and upload it to the basic outputDate: 2011-12-05 click: 2324 Source: Unknown share to:
How to use:Cat[-ABEENSTTUV] [--help] [--version]fileName
Description: Connect the file string to the basic output (screen or add > FileName to another file)
Parameters:
-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
Example:
Cat-n TexTfile1 > Textfile2 put the Textfile1 in the file, and then enter Textfile2 in the file.
Cat-b textfile1 textfile2 >> textfile3 Append the contents of the Textfile1 and Textfile2 to the textfile3 after adding the line number (blank line not added) to the file.
Example:
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
Cat/dev/null >/etc/test.txt This is for emptying/etc/test.txt archive content
Cat can also be used to make image file. For example, to make a soft disc image file, put the floppy
cat/dev/fd0 > OUTFILE
Conversely, if you want to write the image file to a floppy disk, please call
Cat Img_file >/dev/fd0
Note:
1. OUTFILE refers to the image file name of the output.
2. Img_file refers to image FILE.
3. If the device is written back from image file, the device capacity needs to be equivalent.
4. Usually used in the production of the boot magnetic chip.
There are three main features of the Linux Cat command :
The 1.Linux Cat command displays the entire file at once. $ cat
FileName
The 2.Linux Cat command creates a file from the keyboard. $ cat > FileName
Only new files can be created and existing files cannot be edited.
The 3.Linux Cat command merges several files into one file.
$cat
File1 file2 >
File
Parameters:
-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
A blank line that is substituted for a row when it encounters a blank line that has more than two consecutive lines
-V or--show-nonprinting
Example:
Cat-n textfile1 > Textfile2 textfile1
The file, add the line number and enter the Textfile2 file.
Cat-b textfile1 textfile2 >> Textfile3 put Textfile1 and
Textfile2 the contents of the file plus the line number (blank line not added) after attaching the content to the
In the Textfile3.
Example:
Add a line number to the Textfile1 file and enter the Textfile2 file.
Cat-n textfile1 > Textfile2
Put Textfile1 and Textfile2
The contents of the file are appended to the TEXTFILE3 after adding the line number (blank line not added)
In
Cat-b textfile1 textfile2 >> textfile3
Cat/dev/null >/etc/test.txt
This is to empty the/etc/test.txt archive content
Cat can also be used to make image file. For example, to create an image of a floppy disc
File, put the soft disc back and hit it.
cat/dev/fd0 > OUTFILE
Conversely, if you want to write the image file to a floppy disk, please call
Cat Img_file >/dev/fd0
Note:
1. OUTFILE refers to the image file name of the output.
2. Img_file refers to image FILE.
3. If the device is written back from image file, the device capacity needs to be equivalent.
4. Usually used in the production of the boot magnetic chip.13.9. Using cat to manipulate files
REd Hat Linux has a tool program that helps you keep a short list, collect these lists, and even give you a little information about your system.
This tool is called cat, which is a shorthand for CoNCatenate (chain) , which means merging files.
The Cat command also displays the contents of the entire file on the screen (for example, type cat filename.txt). If the file is longer, it will roll over on the screen very quickly. To prevent this effect from happening, use cat filename.txt | Less Command.
Together with the pipe (|) and the less command, the file is displayed page by page. You can then use the UP or DOWN ARROW keys to move forward or backward through the page numbers.
using the re-guide
Re-orientation is to enable the shell to change the standard output it determines, or to change the target of the standard output.
To redirect standard output, use the > symbol. Placing the > symbol after the Cat command (or after any tool and application written to the standard output) redirects its output to the file following the symbol.
For example, using cat itself will output what you have entered on the screen as if it were repeating the line you just typed. The following example shows that cat repeats every line you enter:
Figure 13-5. Cat Command
To redirect cat output to a file, type the following command at the shell prompt (press the [Enter] key to take you to a blank line):
Redirect output to a file
Press the [Enter] key to go to a blank line, and then use the [Ctrl]-[D] key to exit cat.
There is no duplicate display here. This is because cat's standard output has been re-directed. The redirect is a new document you just made, called Sneakers.txt .
When you run the Cat command, you will find the files in your directory (if you want to enumerate these files, type ls).
As shown earlier, you can use cat to read files. At the prompt, type:
Be careful when you redirect the output to a file, because you will easily overwrite an existing file! Unless you want to replace the file, make sure you create a different file name than the one that already exists.
Then redirect the output to another file and call it home.txt. In this example, type the command cat > Home.txt, and then press [Enter] followed by:
bring the coffee home Take off shoesput in sneakersmakesome coffeerelax! |
Now, on a blank 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 two files to a call saturday.txt New file (you will find an example in Figure 13-7). Type the following command:
Cat Sneakers.txt home.txt > Saturday.txt |
Connection file and redirect output
You can see that cat has added home.txt to the end of sneakers.txt .
post-complement standard output
You can use output redirection to add new information after an existing file. This is similar to your use of the > symbol, where you are telling the shell to send information outside of the standard output.
However, when you use >>, you are adding information to the file instead of replacing the file contents completely.
The best way to explain this is to show you the instance. We'll use the two files we just created (sneakers.txt and home.txt) and then connect them using the post-complement output symbols. You want to add the home.txt information to the sneakers.txt information, so type:
Cat Home.txt >> Sneakers.txt |
Now, use the cat sneakers.txt command to check. The final output shows the contents of the home.txt at the end of the file:
Buy some sneakersthen go to the coffee shopthen buy some coffeebring the coffee hometake off shoesput on Sneakersmake some coffeerelax! |
The command you type home.txt the output of the file to the file sneakers.txt .
With the post-fill output, you save yourself time (and some disk clusters) by leveraging existing files without having to create new files.
Now compare the results of file sneakers.txt and file saturday.txt , and you'll see them exactly the same. To make a comparison, type:
Cat Sneakers.txt; Cat Saturday.txt |
The contents of these two files will be displayed-first the sneakers.txt file, then the saturday.txt file
concatenating commands and comparing files
REDIRECT Standard input
Not only can you redirect standard output, you can also redirect standard input.
When you use the redirect standard input symbol <, you are telling the shell that you want to use a file as input to the command.
Use a file that you have created to demonstrate this concept. Type:
Because the less-than sign (<) you use to separate the cat commands and files, thesneakers.txt output is read by the Cat command.
REDIRECT Standard input
A detailed description of how to use the Linux Cat command-connect the file string and upload it to the basic output