Usage differences between grep and find in Linux

Source: Internet
Author: User
Tags svn

Let's introduce the grep usage and some minor considerations


In the process, the most used parameter is-V, but it is not cool to use.

For example, I want to look up a word "userservice", but the document like "*.SVN" doesn't need to be shown, what should I do?

The code is as follows Copy Code

Grep-r "UserService"./| Grep-v "SVN"

However, if similar to a file containing "test, auto_load" and so on I do not show, how to do? My previous practice was:

The code is as follows Copy Code

Grep-r "UserService"./| Grep-v "SVN" | Grep-v "Test" | Grep-v "Auto_load"

The command was long and cumbersome, so I thought that grep itself was based on the regular expression as an option, so I could use the regular expression of the "or |" Command?

The code is as follows Copy Code

Grep-r "UserService"./| Grep-v "Svn|test|auto_load"

It was shown that the execution result showed that the command was not in line with my needs and was puzzled. It turns out that when you use regular expression options, remember to "|" Escape. The final command is as follows:

The code is as follows Copy Code

Grep-r "UserService"./| Grep-v "Svn|prj|test|auto_load"


Here are some interesting command line arguments:

Grep-i pattern Files: case-insensitive search. The default case is case-sensitive,
Grep-l pattern Files: Only the matching file names are listed,
Grep-l pattern Files: Lists mismatched file names,
Grep-w pattern files: matches only the entire word, not part of the string (such as matching ' magic ', not ' magical '),
Grep-c number pattern files: matching contexts show [number] rows,
grep pattern1 | PATTERN2 files: Displays rows that match pattern1 or pattern2.
grep pattern1 Files | grep pattern2: Displays rows that match both PATTERN1 and pattern2.
Here are some special symbols for searching:

< and > mark the beginning and end of the word separately.
For example:
grep man * will match ' Batman ', ' manic ', ' man ' and so on,
grep ' <man ' * matches ' manic ' and ' man ', but not ' Batman ',
grep ' <man> ' matches only ' man ', not ' Batman ' or ' manic ' and other strings.
' ^ ': refers to the matching string at the beginning of the line,
' $ ': refers to a matching string at the end of the line,


Find in Linux


Here are some interesting command line arguments:

Grep-i pattern Files: case-insensitive search. The default case is case-sensitive,
Grep-l pattern Files: Only the matching file names are listed,
Grep-l pattern Files: Lists mismatched file names,
Grep-w pattern files: matches only the entire word, not part of the string (such as matching ' magic ', not ' magical '),
Grep-c number pattern files: matching contexts show [number] rows,
grep pattern1 | PATTERN2 files: Displays rows that match pattern1 or pattern2.
grep pattern1 Files | grep pattern2: Displays rows that match both PATTERN1 and pattern2.
Here are some special symbols for searching:

< and > mark the beginning and end of the word separately.
For example:
grep man * will match ' Batman ', ' manic ', ' man ' and so on,
grep ' <man ' * matches ' manic ' and ' man ', but not ' Batman ',
grep ' <man> ' matches only ' man ', not ' Batman ' or ' manic ' and other strings.
' ^ ': refers to the matching string at the beginning of the line,
' $ ': refers to a matching string at the end of the line,

The difference between grep and find


1.
Find in Linux is equivalent to the search file in win.
Find is a file found in a disk/partition and can be matched with type size time, and the specified file is found by file name or file size or access time.

2.
The grep in Linux is equivalent to the findstr command in win. You can intercept the line with a specific keyword in a txt text and display it.
grep can also use keywords to find multiple files with these keywords in a folder and generate results.

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.