How to use Linux File Command With Example

How to use Linux File Command With Example

In this article we are going to shows how to use file command in Linux. If you want to learn about file command in Linux with Examples then this post is ideal for you.

In the Linux, the file command is a standard program that is used to recognize the type of a file. It is very useful when you will need to find out the type of a file which does not have a file extension.

Linux is an operating system, similar like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).

Linux OS(operating system) is also distributed under an open source license. Open source following these points :

  • Freely to run the program, for any purpose.
  • Free to study how the program works.
  • Freely to re-distribute copies so you can help your friends.
  • Free to distribute copies of your modified versions to others.

How to use file Command in Linux

In the Linux, the basic syntax of the file command is show as below:

file [OPTION] [FILE]

You can pass one or more file names as arguments.

When you run the file command without any arguments or options, it will display the file name along with the file type:

file /etc/timezone
Output
/etc/timezone: ASCII text

You can also pass the multiple files at once to get type of given files:

file /etc/timezone /etc/group
Output
/etc/timezone: ASCII text
/etc/group:    ASCII text

 If you want to find the type of each .mp4 files in the your current directory, run the command below:

file *.mp4

Use -b (–briefoption with the file command if you want to show only file type of given file as show below:

file -b /etc/timezone
Output
ASCII text

If you want to display the mime type of a file, use -i (--mime) option with file command:

file -i /var/www/index.html
Output
/var/www/index.html: text/html; charset=us-ascii

Use -z option if you want to check a compressed files:

file -z filename.tar.gz

Use [range]* option to find the type of files in specific range:

file [a-z]*

If you want to find the type of all files in a particular directory, use directory_name/* option as show below:

file etc/*

For more details about file command, please visit its official page.


That’s all.

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top