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

后端 未结 13 916
走了就别回头了
走了就别回头了 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:25

    Perhaps this would suffice ..

    if ! file /path/to/file | grep -iq ASCII ; then
        echo "Binary"
    fi
    
    if file /path/to/file | grep -iq ASCII ; then
        echo "Text file"
    fi
    

提交回复
热议问题