Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

fgrep subfolders - files

Posted on 2006-11-08
9
Medium Priority
?
646 Views
Last Modified: 2007-12-19
Hi

I have a situation were I need to display the file names that contain the searching word.
I think we can search for word in file using fgrep. But when it come to subfolders or other file how can we do that.
lets say we have root -> subfolder 1 --> file (contain text then diplay file name).
insted of search in one single file how can we do it in all file and subfolder.
It would be great if you have any sample program that has same functionality.

Thanks
0
Comment
Question by:basirana
[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
9 Comments
 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 300 total points
ID: 17899582
If you are searching for whatever, use

grep -ir "whatever" root
0
 
LVL 15

Assisted Solution

by:DonConsolio
DonConsolio earned 300 total points
ID: 17902485
fgrep --files-with-matches --recursive --no-messages 'PATTERN' /path/to/file_or_directoy
0
 
LVL 10

Assisted Solution

by:ssvl
ssvl earned 300 total points
ID: 17905061
why not

find /path/to/directory -name *PATTERN*

i believe that you are searching only for FILENAMES here and not in content.  grep searches through the files and gives you a list of maatches
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Assisted Solution

by:Mysidia
Mysidia earned 300 total points
ID: 17906135
Well, what one should really do is

find /path/to/directory -name '*searchword*'

or

find /path/to/directory -name \*searchword\*

To search for files that have 'searchword' in the filename.

The pattern needs to either be quoted, or you need to escape special characters that the shell is not to interpret.


If the shell you type the 'find' command in does globbing, and you don't quote the pattern, the shell,
can replace  *PATTERN* with the list of any files in the current directory (if any) that happen
to match the pattern, before find even starts.

0
 
LVL 3

Accepted Solution

by:
bryanlloydharris earned 300 total points
ID: 17909204
cd /some/path
grep -R "search-pattern" .

# there is a dot at the end of line 2
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17909615
Hi,

-R switch is to recurse into directories below the current folder
-l switch will display filenames instead of matching line contents

so:

fgrep -R -l  <pattern> *


will match the files with the pattern recursively and will displayy only the names of the files.

Cheers,
K.
0
 
LVL 11

Expert Comment

by:kblack05
ID: 17911067
Find works, but grep with the -R switch is much less system intensive, since find is likely to tap system resources if its a big file structure...

Also check out "egrep"

The -i (ignore case) and -R (recurse substructure) are our friends as KeremE points out.

man find
man grep
man egrep
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17933069
basirana, could you please explain why you have chosen that one as answer? If that works for you, the comment posted a day earlier http:#17899582 should also work.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 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