Using grep to search files provided by find: what is wrong with find . | xargs grep '...'? Using grep to search files provided by find: what is wrong with find . | xargs grep '...'? linux linux

Using grep to search files provided by find: what is wrong with find . | xargs grep '...'?


As Andy White said, you have to use fgrep in order to match for plain ., or escape the dots.

So you have to write (-type f is to only have the files : you obviously don't want the directories.) :

find . -type f | xargs fgrep '...'

or if you still want to use grep :

find . -type f | xargs grep '\.\.\.'

And if you only want the current directory and not its subdirs :

find . -maxdepth 1 -type f | xargs fgrep '...'


'.' matches any character, so you'll be finding all lines that contain 3 or more characters.

You can either escape the dots, like this:

find . | xargs grep '\.\.\.'

Or you can use fgrep, which does a literal match instead of a regex match:

find . | xargs fgrep '...'

(Some versions of grep also accept a -F flag which makes them behave like fgrep.)


@OP, if you are looking for files that contain ...,

grep -R "\.\.\." *