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

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

    Although it is an old question, I think this info bellow will add to the quality of the answers here.

    When ignoring files with the executable bit set, I just use this command:

    find . ! -perm -111
    

    To keep it from recursively enter into other directories:

    find . -maxdepth 1 ! -perm -111
    

    No need for pipes to mix lots of commands, just the powerful plain find command.

    • Disclaimer: it is not exactly what OP asked, because it doesn't check if the file is binary or not. It will, for example, filter out bash script files, that are text themselves but have the executable bit set.

    That said, I hope this is useful to anyone.

提交回复
热议问题