Solved

fgrep subfolders - files

Posted on 2006-11-08
9
641 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 100 total points
ID: 17899582
If you are searching for whatever, use

grep -ir "whatever" root
0
 
LVL 15

Assisted Solution

by:DonConsolio
DonConsolio earned 100 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 100 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 100 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 100 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

Technology Partners: 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!

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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