4

I would like to search all the files in the current directory only. I tried this

grep foo *

but I get this error

grep: bar: Is a directory

I also tried this

grep -r foo

but this is searching subdirectories as well.

Zombo
  • 1
  • 62
  • 391
  • 407

2 Answers2

4

Depending on your version of grep, you may be able to write:

grep --directories=skip foo *
ruakh
  • 175,680
  • 26
  • 273
  • 307
0

This is actually a comment, just don't have enough reputation to place it as a comment. your 1st answer is actually correct.

if bar is a directory within the same directory you want to search files and you don't like the error. It can also be simple just to do away with error. e.g.
grep foo * 2> /dev/null

Mosd
  • 1,640
  • 19
  • 22