list/find all regular files in all subdirectories excluding binary files
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
.
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...)