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

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

    Use utility file, sample usage:

     $ file /bin/bash
     /bin/bash: Mach-O universal binary with 2 architectures
     /bin/bash (for architecture x86_64):   Mach-O 64-bit executable x86_64
     /bin/bash (for architecture i386): Mach-O executable i386
    
     $ file /etc/passwd
     /etc/passwd: ASCII English text
    
     $ file code.c
     code.c: ASCII c program text
    

    file manual page

提交回复
热议问题