When i use the command above, i get wrong matches.....can someone explain me, what is wrong?
I'm trying to search for the string "..." in all files in the current folder.
When i use the command above, i get wrong matches.....can someone explain me, what is wrong?
I'm trying to search for the string "..." in all files in the current folder.
If you are literally typing grep '...'
you'll match just about any string. I doubt you're actually typing '...'
for your grep command, but if you are, the ...
will match any three characters.
Please post more info on what you're searching for, and maybe someone can help you out more.
If you're looking for a filename that matches, try:
find . -name "filename pattern"
or
find . | grep "filename pattern"
If your looking for looking for files that match (ie it contains the grep string)
find . | xargs grep "string pattern"
works fine. or simply:
grep "string pattern" -R *
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.)
To complete Jeremy's answer, you may also want to try
find . -type f | xargs grep 'your_pattern'
or
find . -type f -exec grep 'your_pattern' {} +
Which is similar to a xargs
I might add : RTFM ! Or in a more polite way : use & abuse of
man command
!
@OP, if you are looking for files that contain ...,
grep -R "\.\.\." *