Linux Learning Notes (v) Common Directives 3

Source: Internet
Author: User

1. View file instructions: Cat tail head tac,more, less

Cat, such as CAT/ETC/PASSWD, is more commonly used by people.

And when looking at log, because it is often the most recent content that needs attention, the instruction that is often used is tail

For example, Tail/var/maillog

The TAC output is the opposite of cat order, and the last line is displayed as the first line.

More and less are used when viewing content for a long time, because both support page flipping.

But less is more powerful, it supports flipping forward, and more only supports backward flipping.

In addition to view, there are more useful shortcut keys, G directly to the beginning of the content, G directly to the end of the view content. and '/' query, search, very useful features.
For head and tail, you can see the first 10 lines of the article, or the last 10 lines, and you can also control the number of rows.
Dynamic display of the contents of the file the question was answered incorrectly, and it was taken for granted, to reinforce the impression.
The command to dynamically display the contents of a file is a tail-f file, or a tail-f file.

And these text view instructions, in general, we will use the connector to see the results of multiple instructions running.

For example man locate |more we use more to view the contents of locate manual.

2. Text Editor Vi,vim

Vim is an upgraded version of the VI editor, is a very good file editor,
divided into three modes: General mode, edit mode, command mode
General mode is cursor operation, j down, K move up, H left, l→
can be combined with numbers +j, move down how many rows
Ctrl+f PAGE DOWN, CTRL +b PAGE UP
GG back to the beginning of the document
G back to the end of the document
Shift+4 to line end
O back to the beginning, ^ (shift+6) to the first non-whitespace character

Delete entire Document content action method: Method 1: Press GGDG Method 2::%d

Delete the specified character
Move the cursor to position x the character after the cursor is clipped, shift+x the character before the cursor
Number +x How many characters are clipped
P sticks to the next line of the cursor, and p sticks to the previous line of the cursor
The Undo is u and can be rolled back 50 times.
Ctrl+r Anti-Revocation
DD to specify row deletion
YY Copy a whole line
DD YY can be combined with digital

Enter V (visual mode)
You can choose one piece to do the cutting, etc.
Vim + 10 file, enter the 10th line of the file

Vim edit mode:
I general mode, the cursor does not move, I cursor at the beginning of the line
A cursor moves to the end of the line
A behind the cursor
o cursor moves to the next line
O cursor moves to the previous line

Just accidentally cut two lines, how to recover?
You can, I chose the anti-recovery ctrl+r, understand wrong.


Command mode: Input instruction, such as set line number: Set Nu, cancel line number set Nonu
: Wq Save exit: q! forced exit
/content means find yellow highlight, n jump to next highlight, n jump up
? Also means find, while n jumps up, n jumps down
Replace
Input directives, such as
: 1,100s/iptables/iptables/g
1,100 means 1-100 lines, S is the replacement
Replace the iptables with the iptables,
The g here means all substitutions, and if no g then the iptables of the same line replaces only the first one.
1,$ means that the entire document is equivalent to 1,%
If you are replacing a directory, you need to consider the issue of special symbols
1,%s/\/etc\/sysconfig/\/1111/g
You need to use the decipher symbol to split open
or use other special symbols to separate them.
such as #,1,%s#/etc/sysconig#/1111/g
Requires not to use the special symbols around the division can be

Twice in a row ESC can cancel the command that just knocked the wrong, into the general mode
In addition:/word can also search keywords. I didn't think of that.

Linux Learning Notes (v) Common Directives 3

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.