Grep Binary Files – Resolve ‘Binary File (standard input) Matches’ Error

binaryfilesgrep

I'm on Ubuntu and I typed cat .bash_history | grep git and it returned

Binary file (standard input) matches

My bash_history does exist and there are many lines in it that starts with git.

What caused to display this error and how can I fix it?

Best Answer

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:

.bash_history: data 

You can read a few bytes from start to have a conforming view:

head -c1K .bash_history 

Here I am reading first 1 KiB.

You can pipe the STDOUT to hexdump/od or similar.


As a side note, grep takes filename(s) as argument, so cat is useless here; try this:

grep git .bash_history
Related Question