Solved

Search for specific file content

Posted on 2014-09-15
7
376 Views
Last Modified: 2014-09-15
I would like to do a search to  list  all files that have a particular set of words contained in them, i.e., "digital brochures". I do not want it to be case sensitive.  I would like to do the search of all files in the current directory plus all its subdirectories.

Thank you.
0
Comment
Question by:geeta_m9
  • 3
  • 2
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 400 total points
ID: 40323893
grep -R -i -l "digital brochures" .

Note the dot " ." at the end!

The above will list just filenames with matching content, not the content itself. To see the content along with the filename, omit "-l".
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40323906
Do you want the order specified as well like "digital brochures" or do you want all files that contain both words (anywhere in the file)?
0
 

Author Comment

by:geeta_m9
ID: 40323921
No, I want it in that order for this purpose. For academic purposes, let's say I wanted it the way you suggested. How would the command be modified?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:geeta_m9
ID: 40323927
When I enter the command grep -R -i -l "digital brochures",  the cursor just seems to be stuck in one spot. Does this command take a long time to execute?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40323930
You forgot to type the dot "." at the end. See the note in my first comment!

To your academic question:

grep -E -R -i -l "digital|brochures" .

"-E" means "Interpret the pattern as an extended regular expression", and
the vertical bar ("pipe") means "or".
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 100 total points
ID: 40323944
>> Does this command take a long time to execute?
Depending on how much files you have, yes it can...

grep -iR -l "digital" . 2>/dev/null | xargs grep -iR -l "brochures" 2>/dev/null
0
 

Author Comment

by:geeta_m9
ID: 40323946
Yes, that was the problem. Thank you.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now