Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

in linux how to find files by the keyword in content?

Status
Not open for further replies.

sidneyluo

Newbie level 4
Joined
May 6, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
china
Activity points
1,329
how can i find a file by a key word in the content in liunx? what command can i use?
 

grep [options] pattern [file]

'pattern' would be the word/sentence you're searching for.

Normally grep will output the matching lines from each file, which some (like me) don't find really useful without using the following options :
-n prints the matching line's number.
-l doesn't print the content, just only lists the files with matches found.
-c prints a list of searched files and the count of matches within each.

if you're searching in a directory that contains other directories you'll need to provide the option -r to search recursively. omit it to search the files *just* in this directory.

Also if you are searching within system files, some errors may be generated, so pass grep the option -s to suppress those errors.

last, if your pattern is just one word, you could type the word without any surrounding quotes, if it's sentence, you'll need to write it within double quotes ..

example : searching for "float x" in a source tree :

grep -r [-c -n -l] "float x" *

the asterisk '*' means "all files".

Experiment a little with it till you find the options that work for you.
 

thank mtarek16, thank you for your detailed reply.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top