I need to find some text in one or more files.

This is what I use:

grep -irI "hello" ~/

However, if I want to find a string containing characters like * or _ then these seem to be ignored.

Let's say I want to search in all files for the string a**__.

How can I do that? Many thanks - I just can't figure this out!


There is a -F option:

-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.  (-F is specified by POSIX.)

This will disable searching by regular expressions and interpreting characters like * or .. Example:

$ cat test 
$ grep -F 'a**__' test 
| improve this answer | |

You should use an escape character (\) in front of * because, otherwise, your string to search will became a regular expression.

For example, if you want to search for **__, you can use:

 grep -irI "\*\*__" ~/

More about: In a regular expression, which characters need escaping?.

| improve this answer | |

A simple double quote (" ") with an escape character ( '\' )will do the job.

for example if I want to search for ind*x.html from the current folder I will use :

grep -r "ind\*x.html" ./

Note : If you are not using without quotes then you need to use two backslash.

grep -r ind\\*x.html ./

Both will search for ind*x.html term in the files.

| improve this answer | |

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.