Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find binary files in a directory?

Tags:

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?

like image 995
Kiss-Budai Matyas Avatar asked Apr 08 '15 14:04

Kiss-Budai Matyas


1 Answers

This finds all non-text based, binary, and empty files.

Edit

Solution with only grep (from Mehrdad's comment):

grep -rIL . 

Original answer

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


Edit 2

This finds all non-empty binary files:

find . -type f ! -size 0 -exec grep -IL . "{}" \; 
like image 95
t.animal Avatar answered Sep 28 '22 00:09

t.animal