My Ops Journey-find text for Linux commands

Source: Internet
Author: User

Small partners must have met so embarrassing scene, the problem of online service, the boss has been asked what the problem caused, and you because of the command to find text is not too familiar, tinker for a long time to find that abnormal log, and then perhaps half an hour has passed. The boss may be disappointed in you. The truth is that I am such a little white. Learn from the bitter, crazy understanding of the use of various search commands.

Common Text Lookup commands

Cat command

format : Cat [-ns] File

Options :

-N Display Line number

-S blank line does not output

This is useful for finding files two options, other relevant options can be self-Baidu

More Commands

Format: More [-spcl][-number][+number][+/pattern] file

options :

-S blank line does not output

-number How many rows are displayed

-L ignores page break symbols inside the file

-p to page a file by clearing the window instead of scrolling, similar to the-C option

+linenumber Show content under LineNumber

+/pattern starts the first two lines of the field that appear

operation command :

Ctrl+f a page forward

Ctrl+b back one page

Space down one page

Enter down one line

= Display the current line number

: F Displays the document name, the current line number

Q Exit More command

Less command

format: Less [-ni] File

Options

-N Display Line number

-I ignores case when finding matching fields

Operation Command :

/pattern Query the field down

? Pattern queries the field up

N Repeat previous Search

N Reverse repeats previous search

PageUp a page forward

PageDown down one page

Carriage return down one page

Space down one line

Tail command

format : tail [-FN] File

Options :

-F Monitoring File latest input

-N shows how many rows

grep command

format :grep [-abc][number] [--color=auto] Pattern file

Options :

-C number displays the upper and lower number lines of the matching field

-B number Displays the first number row of the field

-A number displays the following number line for the field

--color highlighting

SED command

format :sed-n ' n,mp ' file

options :

-N Static display

This command is used to display the contents of n rows to m rows

Combination of commands used

case1: There was a problem with the online service, a few hours before the problem, I know the problem of a few key words to do?

fix : Cat fileName |grep "xxx"--color=auto

Case2: I want to grab the last 30 of the log and highlight the line with ' exception '

Solution : TAIL-FN-fileName |grep ' exception '--color=auto;

case3: I'm probably in the position of the problem, but I still need to look at the log content for this period to determine

resolution : Cat-n fileName |grep ' exception ' observe the downlink number

Sed-n ' 10,20p ' fileName displays the contents of this line number, and then you take a look at it.

My Operations Journey-find text for Linux commands

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.