Url:http://hi.baidu.com/min_jenery/blog/item/9ecbfffbc92ad1909f5146aa.html
Tail-f/(log file directory) View log commands
CTRL + C Stop printing
Ls-al view file details path, etc.
VI/(log file directory) Open log
/Search Characters
Exit: Press ESC, press ":", enter Q, and hit enter
WinSCP
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.: Z)
3. Merge several files into one file. $cat file1 file2 > file "t?=\
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 row that has more than two consecutive lines, replace the blank line with one line!
-V or--show-nonprinting
Example:
Cat-n textfile1 > Textfile2 Add the file contents of the Textfile1 and enter the Textfile2 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/fd0e
Note:© Newboys--Newboys General Forum
1. OUTFILE refers to the image file name of the output.
2. Img_file refers to the 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.Array. 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 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. For more information about using pipelines to combine two different features, see
Section 13.10
。
13.array.1. 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):
Cat > Sneakers.txt
Figure 13-6. 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.
Notice that the
Figure 13-6
In the difference? 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 them) Wu ┪???? LS).
As shown earlier, you can use cat to read files. At the prompt, type:
Cat Sneakers.txt
Be careful
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 Shoes
Put on sneakers
Make some coffee
relax!
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 new file called Saturday.txt (you will
Figure 13-7
An example is found in the. Type the following command:
Cat Sneakers.txt home.txt > Saturday.txt
Figure 13-7. Connection file and redirect output
You can see that cat has added home.txt to the end of Sneakers.txt.
13.array.2. 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 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 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
Will the contents of these two files be displayed? First the Sneakers.txt file, then the Saturday.txt file (e.g.
Figure 13-8. concatenating commands and comparing files
13.array.3. REDIRECT Standard input
Not only can you redirect standard output, you can also redirect standard input.
When you use the redirect standard input symbol
Cat
The sneakers.txt output is read by the cat command because you are separating the cat commands and files with a less than sign.
1. Cat command:
Function: 1) Displays the entire file.
Example: $ cat FileName
2) Connect the file string to the basic output, such as merging several files into one file or output to the screen.
Example: $ cat file1 file2 > file
Description: Connect the file string to the basic output (screen or add > FileName to another file)
Detailed Cat 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
2. More Commands:
View the log as a percentage.
3. Less command:
Similar to more features, but less support to scroll through the file.
4. Head command:
Function: From the beginning of the text file, the Head command is used to view the beginning of a text file.
Examples are as follows:
Head Example.txt Displays the first 10 lines of the file example.txt;
Head-n Example.txt Display the first 20 lines of the file example.txt;
Head Detail:
-n Specifies how many lines of text you want to display.
-N Number This parameter option must be a decimal integer and it will determine the position in the file in the behavior unit.
-C Number This parameter option must be a decimal integer, which determines the position in the file, in bytes.
5. Tail Command:
function: The tail command is used to display the end lines of a text file.
Examples are as follows:
Tail Example.txt Display the following 10 lines of the file example.txt;
Tail-n example.txt Display the file example.txt the following 20 lines of content;
Tail-f Example.txt Displays the following 10 lines of the file Example.txt and automatically displays the contents of the new file after the contents of the file have been increased.
tail-n 50-f Example.txt displays the following 50 lines of the file Example.txt and automatically displays the contents of the new file after the contents of the file have been increased.
Note:
Last command is very useful, especially when monitoring log files, you can always display new log information on the screen.
Tail Detailed:
-B number starts reading the specified file from the 512-byte block position represented by the number variable.
-c number reads the specified file starting at the byte position represented by the number variable.
-F If the input file is a regular file or if the filename parameter specifies a FIFO (first in, out),
Then the tail command will not terminate after the last specified unit of the input file has been copied, but continue
Read and copy additional units from the input file (when these units are available). If you do not specify a File parameter,
And the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files that another process is writing.
-K number reads the specified file starting at the 1KB block position represented by the number variable.
-m number starts reading the specified file from the multibyte character position represented by the # variable. Use this flag to provide consistent results in a single-byte and double-byte character code set environment.
-N number reads the specified file from the first or last row position, represented by the sign of the number variable (+ or-or none), and is shifted by the Line No.
-R Displays the output in reverse order from the end of the file. The default value of the-R flag is to display the entire file in reverse order. If the file is larger than 20,480 bytes, then the-r flag displays only the last 20,480 bytes. -R Flag only
is valid with the-n flag. Otherwise, it will be ignored.
The VI Editor is the standard editor for all UNIX and Linux systems, and its power is not inferior to any of the latest text editors, here is simply a brief introduction to its usage and a small number of instructions. Because the VI editor is exactly the same for any version of UNIX and Linux systems, you can learn more about it in any other place where VI is introduced. VI is also the most basic text editor in Linux, after learning it, you will be in the world of Linux unimpeded.
1, VI of the basic concept
Basically, vi can be divided into three states, namely command mode, insert mode (and bottom line mode), and the function of each mode is as follows:
1) command-line mode
Controls the movement of the screen cursor, the deletion of characters, words, or lines, moving and copying a section and entering insert mode, or to last line mode.
2) Insert mode
Only in the Insert mode, you can do text input, press "esc" to return to the command line mode.
3) Bottom Line mode
Save or Exit VI, or you can set the editing environment, such as looking for a string, listing line numbers ... such as
In general, however, we simplify the VI into two modes when we use it, that is, the bottom row mode (last line mode) is also counted as the command-line pattern.
2, VI of the basic operation
A) Enter VI
After the system prompt symbol to enter VI and file name, go to the VI Full screen editing screen:
$ VI myfile
However, it is important to note that after you enter VI, you are in command mode and you want to switch to insert mode to enter text. First Use VI people will want to use the next key to move the cursor, the result of the computer has been a beep, the gas to death, so enter the VI, do not move, switch to "insert mode" and then!
b) switch to insert mode to edit the file
Press the letter "i" under Command mode to enter "Insert Mode", and you can start typing the text again at this point.
c) Toggle of Insert
You are currently in "Insert Mode", you can only enter text, if you find the wrong word! To move back with the cursor key, delete the word, then click the "esc" key to go to "command mode" and then delete the text.
d) Exit VI and save the file
Under Command mode, click the ":" colon key to enter "last line mode", for example:
: w filename (enter "w filename" to save the article with the filename you specified)
: Wq (input "wq", save and Exit VI)
: q! (Enter q!, do not save the mandatory exit VI)
3. Command mode function key
1). Insert mode
Press "i" switch into insert mode "insert mode", press "I" into the insertion mode is the beginning of the cursor from the current position to enter the file;
After pressing "a" into insert mode, the text is entered from the next position at the current cursor position;
When you press "o" to enter insert mode, you insert a new line and enter text from the beginning of the beginning.
2). Switch from insert mode to command line mode
Press the "esc" key.
3). Move the cursor
VI can be directly on the keyboard with the cursor to move up and down, but the normal VI is the lowercase English letter "h", "j", "k", "l", respectively, control the cursor left, bottom, upper, and right one grid.
Press "ctrl"+"b": The screen moves one page to the back.
Press "ctrl"+"f": The screen moves one page to the front.
Press "ctrl"+"u": The screen moves the half page toward the back.
Press "ctrl"+"d": The screen moves the half page toward the front.
"0" by number: Moves to the beginning of the article.
Press "g": Move to the end of the article.
Press "$": Moves to the end of the line where the cursor is located.
Press "^": Moves to the beginning of the line where the cursor is located
Press "w": Cursor jumps to the beginning of the next word
Press "e": Cursor jumps to the end of the next word
Press "b": Cursor back to the beginning of the last word
Press #l: The cursor moves to the first # position of the line, such as: 5l,56l.
4). Delete text
"x": Each time you press the cursor, delete the "after" character at the position where the pointer is located.
#x: For example, "6x" represents the "after" 6 characters of the location where the cursor was deleted.
"x": Uppercase X, each time it is pressed, deletes the "front" character at the location of the cursor.
"#X": for example, "20x" represents the "front" 20 characters of the location where the cursor was deleted.
"dd": Delete the line where the cursor is located.
"#dd": Deletes the # line starting at the line where the cursor is located
5). Copy
"yw": Copies the characters from the cursor to the end of the word into the buffer.
"#yw": Copy # words to Buffer
"yy": Copy cursor line to buffer.
"#yy": for example, "6yy" represents a copy of 6 lines of text from the line where the cursor is located.
"p": Paste the characters in the buffer to the cursor location. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.
6). Replace
"r": Replaces the character at which the cursor is located.
"r": Replaces the character where the cursor is located until the "esc" key is pressed.
7). Reply to Last action
"u": If you mistakenly execute a command, you can press "u" immediately to go back to the previous action. Multiple replies can be performed by pressing "U" multiple times.
8). Change
"cw": Change the word-to-tail at the cursor location
"c#w": For example, "c3w" represents a change of 3 words
9). Jump to the specified line
"ctrl"+"g" lists the line number of the line where the cursor is located.
"#G": for example, "15g", which means moving the cursor to the beginning of the 15th line of the article.
4. Next line Mode command brief
Before using "last line mode", remember to press "esc" to make sure you are under "command mode" and then press ":" Colon to enter "last line mode".
A) List line numbers
"set nu": After you enter "set nu", the line numbers are listed before each line in the file.
B) jump to a line in the file
The "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as entering the number 15, and then enter, you will jump to the 15th line of the article.
C) Find characters
"/Keyword: First press the"/"key, and then enter the character you want to look for, if the first keyword is not what you want, you can always press"n"will look back to the keyword you want.
"? keyword": Press "?" first Key, and then enter the character you want to find, if the first keyword is not what you want, you can always press "n" will look forward to the keyword you want.
D) Save the file
"w": Enter the letter "w" the colon to save the file.
E) Leave VI
"q": Press "q" is to exit, if you cannot leave VI, can be "q" followed by a "!" Forced to leave VI.
"qw": Generally recommended to leave, use with "w", so you can also save the file when exiting.
5. VI Command List
1. The following table lists the functions of some keys in the command mode:
H
Move left cursor one character
L
Move the cursor one character to the right
K
Move the cursor up one line
J
Move the cursor down one line
^
Cursor moves to the beginning of the line
0
Number "0", the cursor moves to the beginning of the article
G
Cursor moves to the end of the article
$
Move cursor to end of line
Ctrl+f
Flip the screen forward
Ctrl+b
Flip the screen backwards
Ctrl+d
Turn Half-screen forward
Ctrl+u
Turn Back half screen
I
Insert a character before the cursor position
A
The next character at the cursor position begins to increment
O
Insert a new row, starting at the beginning of the line
Esc
Fallback from input state to command state
X
Delete the character following the cursor
#x
# characters after the cursor is deleted
X
(uppercase x), delete the character in front of the cursor
#X
Delete the # characters before the cursor
Dd
Delete the line where the cursor is located
#dd
Remove the # line from the number of lines that the cursor contains
yw
Copy a word where the cursor is located
#yw
Copy the # Word where the cursor is located
Yy
Copy a row where the cursor is located
#yy
Copy the # line from the number of lines where the cursor is located
P
Paste
U
Cancel operation
cw
Change a word in the position of your cursor
#cw
Change the # Word where the cursor is located
2, the following table lists some instructions in the line command mode
W filename
Save the file you are editing as filename
WQ filename
Save the file being edited as filename and exit VI
Q!
Discard all changes, exit VI
Set Nu
Show line Numbers
Or?
Find, enter what you are looking for in/after
N
with/or, if the search is not the keyword you are looking for, press N or backwards (with/to) or forward (with?) to continue looking until you find it.
For the first use VI, there are a few notes to remind:
1. When you open a file with VI, you are in command mode, and you want to switch to insert mode to enter text. Toggle method: Click on the letter "i" "Command mode" to enter "Insert Mode", then you can start to enter the text.
2, after editing, you need to switch from insert mode to command line mode in order to save the file, switch method: Press the "esc" key.
3. Save and exit the file: Enter in command mode: WQ! (Don't forget to wq the front:)
Simple command to view Linux under logs with SECURECRT