Linux grep command operation guide

Source: Internet
Author: User

① Definition

Grep is a row-level device that analyzes a row of information. If there is any information we need, the whole row is returned.

② Function

Compares string data to print the strings that meet your needs.

③ Format

Grep [-acinv] [-- color = auto] 'query string' filename

Parameters:
-A: searches for data in the format of a binary file and a text file.
-C: calculates the number of times a 'query string' is found.
-I: case-insensitive
-N: Output row number
-V: displays the row without the 'query string' content.
-A: numbers can be added to the end, which means that, apart from listing the rows, the subsequent n rows are also listed.
-B: numbers can be added to the end, which means before. In addition to listing this row, the preceding n rows are also listed.
-- Color = Auto: Color of keywords

④ Example
Eg01: Identify the identifier of a checkpoint event

[oracle@localhost bdump]$ grep -in --color=auto 'checkpoint' alert_orcl.log64:  checkpoint is 44607466:  checkpoint is 44607469:  checkpoint is 44607472:  checkpoint is 446074383:  checkpoint is 4602001845:Checkpoint not complete2112:  checkpoint is 6062172114:  checkpoint is 6062172116:  checkpoint is 6062172118:  checkpoint is 6062172120:  checkpoint is 606217

Eg02: find information about the NIC from the kernel

[oracle@localhost bdump]$ dmesg | grep -n -A3 -B2 --color=auto 'eth'599-iscsi: registered transport (iser)600-iscsi: registered transport (be2iscsi)601:eth0: no IPv6 routers present602-Bluetooth: Core ver 2.10603-NET: Registered protocol family 31604-Bluetooth: HCI device and connection manager initialized--615-ip_conntrack version 2.4 (8192 buckets, 65536 max) - 228 bytes per conntrack616-ip6_tables: (C) 2000-2006 Netfilter Core Team617:peth0: Promiscuous mode enabled.618:device peth0 entered promiscuous mode619:xenbr0: port 1(peth0) entering forwarding state620-device vif0.0 entered promiscuous mode621-New device vif0.0 does not support netpoll622-Disabling netpoll for xenbr0--625-hdc: drive_cmd: error=0x04 { AbortedCommand }626-ide: failed opcode was: 0xec627:eth0: no IPv6 routers present628:xenbr0: port 1(peth0) entering disabled state629:xenbr0: port 1(peth0) entering forwarding state

 

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.