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.

Is there a way to specify to find that I only want text files (and not binary files)? Grep has an option to exclude binary files, so I thought find probably has a similar feature, but I've been unable to find it.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

That's because grep looks at the file's contents.

find . -exec sh -c "file -b --mime-type {} | grep -q '^text/'" \; -print
share|improve this answer
    
In Ubuntu this is find . -exec sh -c "file -b --mime {} | grep -q '^text/'" \; -print –  icc97 Jul 4 '12 at 21:28
add comment

find can find files by their metadata, but not check contents. However, you can couple it with file:

find .git -type f -exec file -iN0 {} + |
awk -F '\0' '$2 ~ /^: text\// {print $1}'

(You can remove the | awk ... part if you also want more detailed information.)

share|improve this answer
add comment

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.