Linux command: How to 'find' only text files?

前端 未结 16 907
孤街浪徒
孤街浪徒 2020-12-02 04:43

After a few searches from Google, what I come up with is:

find my_folder -type f -exec grep -l \"needle text\" {} \\; -exec file {} \\; | grep text
         


        
16条回答
  •  执念已碎
    2020-12-02 05:15

    Here's how I've done it ...

    1 . make a small script to test if a file is plain text istext:

    #!/bin/bash
    [[ "$(file -bi $1)" == *"file"* ]]
    

    2 . use find as before

    find . -type f -exec istext {} \; -exec grep -nHi mystring {} \;
    

提交回复
热议问题