Use “file” command to determine the type of file

Share this post to your friends !

This entry is part 2 of 6 in the series Linux commands: Part 3 - Exploring the system

WriteBash - 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.

use-file-command-to-determine-the-type-of-a-file-01 Use "file" command to determine the type of file
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.

use-file-command-to-determine-the-type-of-a-file-02 Use "file" command to determine the type of 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 install.zip. 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.

use-file-command-to-determine-the-type-of-a-file-03 Use "file" command to determine the type of file
file command with option -z

For the other parameters of the file command, type:

file --help

Conclusion

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.

Continue reading the series«« Previous part: ls – Listing the contents of a directoryNext part: Use less command to view long text documents »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.


Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.