0

I tried to display with grep -rIL the binary files from a directory (subdirectories included) but after I tried it I'm not sure if the output is right. Could someone please tell me if grep -rIL outputs binary files or is there a better way to display binary files with grep?

1 Answer 1

1

Man page says:

-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.

That's what it looks like to do, too:

$ printf 'foo\0bar\0' > binary.txt
$ echo hi > hello.txt
$ grep -rIL -e foo .
./hello.txt
./binary.txt
$ grep -rL -e foo .
./hello.txt
$

With -I the binary is listed, like the non-matching non-binary file; without it, it's not.

3
  • @ikkachu,so grep -rL would be the right way?I don't really understand what is considert a binary file Commented Mar 24, 2021 at 22:11
  • @pleasehelp, err, depends on what you want to actually do in the end. Grep considers files "binary" if there's any NUL bytes, or if there's other data that doesn't match characters in the current locale (e.g. broken UTF-8 encoding, in a UTF-8 locale). -IL would treat all binary files as non-matching and would list all non-matching files, so it should print the binary files. Though if doing it with grep makes sense, you'll have to decide. Also note: unix.stackexchange.com/questions/510044/… Commented Mar 24, 2021 at 22:50
  • @ikkachu thank you. It's for an exercise and it specifies that I should display with the help of grep all binary files and I got a little bit confused. Commented Mar 24, 2021 at 22:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.