« Back to File systems: Frequently Asked Questions

How to see the file type on Linux

How to see the file type on Linux?

Run the file command to inspect a file and see what file type it might be.

file /path/to/file

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.

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • cat
  • file

Other questions related to Linux file systems

    Related articles

    Like to learn more? Here is a list of articles within the same category or having similar tags.

    Feedback

    Small picture of Michael Boelen

    This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

    Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

    Mastodon icon