How to see the file type on Linux
The file command is available on Linux systems to retrieve file information. It can determine the file type by analyzing specific sections of the file and return the most likely file type. The first few lines of a file often reveal the file type. But since a file can be binary data, it may mess up the terminal output when using the cat command.
Examples using file
The /etc/passwd file is a good target to see an example of a plain text file.
# file /etc/passwd
/etc/passwd: ASCII text
To see the output of a binary file, we can inspect /bin/ls.
# file /bin/ls
/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=36b86f957a1be53733633d184c3a3354f3fc7b12, for GNU/Linux 3.2.0, stripped
Depending on the file, additional details are provided. As can be seen in the example above, it does not just show it is an executable file (ELF), but also the processor platform, how it is linked, a build hash, and that debug symbols are stripped.