Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Linux.

I know I can do find . -type f, but that includes binary file and I couldn't find a way to exclude them with find

share|improve this question
    
What constitutes "binary"? All files are binary when you get down to it. –  Billy ONeal Oct 5 '10 at 1:08

4 Answers 4

up vote 5 down vote accepted

file /usr/bin/file, for example, does not include the word "binary" in its output on my system. If file -i is available, it does include the word "binary". Without -i, it may be more reliable to test for the presence of the word "text".

find -type f -exec sh -c "file {} | grep text >/dev/null" \; -print

or

find -type f -exec sh -c "file {} | grep text >/dev/null" \; -ls

Using -i:

find -type f -exec sh -c "file -i {} | grep -v binary >/dev/null" \; -print

Using file is only going to be an approximation since it's using heuristics to determine the type of file and there's no hard-and-fast definition of what constitutes a "binary" file. Is an empty file "binary"? file says it is. Also, there are lots of (normally uncommon) ways to trigger false positive IDs by file.

share|improve this answer

Another way would be to exclude all files which have execute permission set for either user, group or others:

find . -type f ! -perm /u=x,g=x,o=x

(If binary equals execute permissions...)

share|improve this answer

show all files without executable permissions (although this is not specifically binary, so it may not be exactly what you need):

ls -l | awk '{if ($1 !~ /x/) print $8}'
share|improve this answer
1  
I thought of a similar thing, but worried that executable != binary. Nevertheless, you can do this just with find as well: find . -type f \! -executable –  Telemachus Oct 5 '10 at 0:32
find . -type f -exec file "{}" | grep -vE "ELF|archive"
share|improve this answer
    
you might need \; after "{}". –  Dilawar Oct 12 '13 at 9:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.