How to check if the file is a binary file and read all the files which are not?

后端 未结 13 913
走了就别回头了
走了就别回头了 2020-12-05 16:58

How can I know if a file is a binary file?

For example, compiled c file.

I want to read all files from some directory, but I want ignore binary files.

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 17:36

    Try the following command-line:

    file "$FILE" | grep -vq 'ASCII' && echo "$FILE is binary"
    

提交回复
热议问题