Why does grep return binary file matches?

Why does grep return binary file matches?

If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option. Warning: grep –binary-files=text might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands.

How do I grep a string in binary?

To force GNU grep to output lines even from files that appear to be binary, use the -a or ‘ –binary-files=text ‘ option. To eliminate the “Binary file matches” messages, use the -I or ‘ –binary-files=without-match ‘ option, or the -s or –no-messages option.

What does binary file matches mean?

Binary file [some_file] matches. …this is what’s happening… [from the grep man page] Normally, if the first few bytes of a file indicate that the file contains binary data, grep outputs only a message saying that the file matches the pattern. To force the file to be treated as text, use the -a (or –text) option.

What causes grep to return ” binary file matches “?

Error is due to the data in the file being binary, you can use strings command to see the human readable (i.e. strings) part which you would normally search using grep This can be caused by null bytes in your bash history. Removing lines with null characters may resolve the issue.

When to use without match in grep command?

If TYPE is without-match, grep assumes that a binary file does not match; this is equivalent to the -I option. If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option.

Why does grep treat Bash history as binary?

Presumably the file .bash_history starts with non-text data, hence grep is treating the file as binary. This is confirmed by the file .bash_history output: Here I am reading first 1 KiB.

When to use the-I option in grep?

If TYPE is without-match, grep assumes that a binary file does not match; this is equivalent to the -I option. If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option.