Linux command-grep

Source: Internet
Author: User

  1. Command format:

    grep [options] Find condition directory file

  2. Command function:

    For filtering, searching for specific characters

  3. Common options:

    -A (number) displays the (number) row after the line, in addition to the line that matches the criteria

    - B (number) displays the line before the line, in addition to the line that matches the criteria

    - C (number) displays the front and back (number) lines of the row, in addition to the line that matches the criteria

    -I ignore case when searching

    - v show rows that do not contain criteria

    - n Displays the row where the condition is located and lists the line number of the row

  4. Common examples:

    Example one: Filtering out the specified process sshd

    Command: PS aux | grep sshd

    Example two: Filter out the file with the keyword "Zhe" line, and display the line number of these lines

    Command: grep-n "the" file

    Example three: Filter out the file "a" begins with "a" line, ending with "Z"

    Command: grep "^a" file | grep "z$"

    Example four: Blank lines in file files are not displayed

    Command: grep-v "^$" file

Linux command-grep

Related Article

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.