1

I have bunch of directories with each and every one of them containing a file. Now some of these files are hidden. I need to find a string that's in one of the hidden files.

I tried

fgrep -r "*medium*" .

find . | fgrep '*medium*'

medium is the string that I need to find. None of these commands find the word that I need.

  • 1
    Is the string you are searching for medium or *medium*? – steeldriver Nov 5 '16 at 3:25
  • Please clarify your question if it hasn't been answered. – pfnuesel Nov 5 '16 at 7:25
3
grep -r --include=.* medium .

man grep:

   --include=GLOB
          Search  only  files whose base name matches GLOB (using wildcard
          matching as described under --exclude).
  • Aren't hidden files searched anyway? – pfnuesel Nov 5 '16 at 1:45
  • 1
    Yes, but the question was to search in hidden files only. – Ipor Sircer Nov 5 '16 at 1:46
  • This one doesn't find it either. I think my question is not clear. There are bunch of text files in every single sub directory and all of them has the string "Hello world" that one i can find easy. what i need to find is the one with the string "medium". – Saja Peiris Nov 5 '16 at 2:36
  • If you're using the wildcard to match a regexp, use grep -rE (you must understand what the wldcard means in this case). if you're searching for the exact string, use grep -r "medium" or fgrep -r "medium". – jai_s Nov 5 '16 at 4:04
  • I think the question isn't clear. This answers it as stated, but I suspect @SajaPeiris means the file is hard to find rather than actually "hidden." (Just a suspicion based on the wording of the question and the comment above.) Or, the file is hidden using e.g. macOS Finder settings rather than a dot-name. Anyway, upvoted for the --include flag. – Wildcard Nov 5 '16 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.