Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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


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

Example using Python and shell:

IS_BINARY='import sys; sys.exit(not b"\x00" in open(sys.argv[1], "rb").read())'
find . -type f -exec bash -c "python -c '$IS_BINARY' {} || echo {}" \;

The key element is in:

b"\x00" in open("", "rb").read()

which checks if the file has NULL character.

share|improve this answer

Try the following command:

find . -type f -exec file "{}" \; | grep -vE "ELF|archive"
share|improve this answer
you might need \; after "{}". – Dilawar Oct 12 '13 at 9:50

If you mean regular files which basically doesn't contain NULL characters, try using GNU grep:

grep -PaLr '\x00' .
share|improve this answer

Your Answer


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.