DelphiFAQ Home Search:

Recursively find all documents that match a file name and contain a string

 

comments2 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

Question:

I need to recursively find all documents where the file name matches a certain pattern ('index*') and that contain a certain string ('update'). How do I do this in Linux?

Answer:

You need a combination of find to locate those index* files and grep to only list those that have the keyword 'update' in it.

The following command will do the trick.

Note: if you want a 'negative search', meaning list all documents that do NOT contain 'update', then add the -v parameter to grep.

# -l lets grep just put out the filename
find index* -exec grep -l update {} \;


# -v does a negative search
# show all documents that do NOT contain 'update'
find index* -exec grep -l -v update {} \;

Comments:

2006-11-15, 01:09:55
anonymous from Taiwan  
rating
Thank you for providing the answer I was looking for, too!
2008-10-21, 08:16:58
anonymous from Romania  
find index* -exec grep -l -v update {} \;
Will not work. it will match any file that does contain something else besides 'update' in it.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: