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

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

4 Answers

up vote 2 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.

link|improve this answer
feedback

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}'
link|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
feedback

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...)

link|improve this answer
feedback
find . -type f -exec file "{}" | grep -vE "ELF|archive"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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