Link to home
Start Free TrialLog in
Avatar of basirana
basirana

asked on

fgrep subfolders - files

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
SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kerem ERSOY
Kerem ERSOY

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.
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
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.