?
Solved

Search for specific file content

Posted on 2014-09-15
7
Medium Priority
?
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 

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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 400 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

764 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