Use “file” command to determine the type of file

by Daniel Pham
Published: Updated:
This entry is part 2 of 6 in the series Linux commands: Part 3 - Exploring the system

Sometimes while working with Linux systems, you will see the type of file that you may have never known before.

Linux supports you with a command you can determine the type of file. This command is quite simple but it can be useful for you in some cases.

Show type of file with “file” command

As you can see, the name of the command says its meaning, the file command is used to determine the type of the file.

file command
file command

The simplest is to call the file command and the name of the file you need to determine behind that.

file name-of-the-file

The example below, I will determine the type of file install.log – this is a common file when you install CentOS virtual servers. The results showed that this is an ASCII text file.

determine the type of a log file
Determine the type of a log file

So what if you want to check what kind of file is in a compressed file? In this case, we will use the -z parameter in the file command.

  • -z: try to look inside compressed files.

In the example below, I have compressed the install.log file into a compressed file named When we use the file command to test the compressed file, it returns the result as a zip file. But when we use the parameter -z, it will return results about the type of files inside compressed files.

file command with option -z
file command with option -z

For the other parameters of the file command, type:

file --help


File commands can be very simple (I’m trying to talk about the simplest thing) but it can be very helpful for you in the future. For example, you download a compressed file for installation, but you do not know what exactly is inside the compressed file. When you extract the file, can you spread the virus? I suppose so, then the file command will help you somewhat in this case.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Series Navigation«« Previous part: ls – Listing the contents of a directoryNext part: Use less command to view long text documents »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.