Solved

fgrep subfolders - files

Posted on 2006-11-08
9
629 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
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
 
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINUX, CPANEL & WHM 5 44
Automating a script for user accounts LINUX 14 70
AWS vpc peering connection 1 43
Linux as a middle box 7 64
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

867 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

16 Experts available now in Live!

Get 1:1 Help Now