I need to find the binary files in a directory. I want to do this with file, and after that I will check the results with grep. But my problem is that I have no idea what is a binary file. What will give the file command for binary files or what should I check with grep?
This finds all non-text based, binary, and empty files.
Solution with only grep (from Mehrdad's comment):
grep -rIL .  This does not require any other tool except find and grep:
find . -type f -exec grep -IL . "{}" \;  -I tells grep to assume binary files as unmatched
-L prints only unmatched files
. matches anything else
This finds all non-empty binary files:
find . -type f ! -size 0 -exec grep -IL . "{}" \; 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With