Ubuntu – How to use ‘grep’ with characters like * and _

command linefind

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!

Best Answer

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 
a**__
$ grep -F 'a**__' test 
a**__