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

前端 未结 16 911
孤街浪徒
孤街浪徒 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 04:53

    I do it this way: 1) since there're too many files (~30k) to search thru, I generate the text file list daily for use via crontab using below command:

    find /to/src/folder -type f -exec file {} \; | grep text | cut -d: -f1 > ~/.src_list &
    

    2) create a function in .bashrc:

    findex() {
        cat ~/.src_list | xargs grep "$*" 2>/dev/null
    }
    

    Then I can use below command to do the search:

    findex "needle text"
    

    HTH:)

提交回复
热议问题