LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-07-2015, 10:32 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,773

Rep: Reputation: 138Reputation: 138
grep -r does not serach .directories?


I am using grep as e.g.

grep -r "mystring" *

However, if a file containing "mystring" is in ./.hiddenDir, grep does not find it. If I:

grep -r "mystring" .*

It does find it, but multiple times because it searches ./.hiddenDir, ../current/.hiddenDir and .hiddenDir

Is there a way to make grep -r search folders in the cwd beginning with dot?

Yes, I know I can do this with find, but I want grep.

(Slackware 64 14.1 - up-to-date)
 
Old 12-07-2015, 10:38 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,429

Rep: Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029Reputation: 2029
It's got nothing to do with grep. It's your shell that is expanding the "*", and all grep sees is the result of that expansion. By default, the shell does not include dotfiles when it does pathname expansion.

If you simply pass "." as the argument to grep:
Code:
grep -r "mystring" .
then grep will start in the current directory and recurse into anything it finds there, "dot" directories and files included.
 
Old 12-08-2015, 09:41 AM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,773

Original Poster
Rep: Reputation: 138Reputation: 138
Yup! That did it! Thanks.
 
  


Reply

Tags
grep, recursive


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] grep many files in multiple directories using patterns from a file francy_casa Linux - Newbie 4 04-12-2012 08:49 AM
GREP Excluding Hidden Directories from being scanned metallica1973 Programming 6 01-12-2012 04:17 PM
[SOLVED] Hiding directories and file-types from grep? Shay Linux - General 1 08-19-2011 03:38 PM
need to search (grep) multiple directories red_nexus Linux - Newbie 5 07-04-2006 10:44 PM
Using Grep to search all sub-directories yrraja Solaris / OpenSolaris 2 08-28-2004 03:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration