Knowledge Base
MilesWeb / VPS FAQ

Steps to Use the Linux File Command

Approx. read time : 4 min

There are several Linux commands that are useful for beginners and experienced too. One of the commands is the Linux file command. This typical application in Linux decides what kind of data is saved in a specific system file. It describes the file type in a format that is understandable, otherwise known as a MIME type. In this tutorial, you will learn the basics of using the Linux file command, and the way it can authorize your VPS management.

Filenames in UNIX can be completely free of the file type as the Linux file command will easily disclose what the type is. May it be an audio, open document spreadsheet or text editor file, the Linux file command will displays its type in a readable form.

How to Use the Linux File Command?

This command can be used for various things. It helps to understand the reasons behind the users’ inability to read a certain file on the system. Additionally, it also helps to determine the type of folder, socket, FIFO (pipes) and helps block special files. Only zero-length files in the Linux system are viewable by File command.

Linux File Command Syntax

Make sure that you access your VPS with SSH, before using the command. The basic syntax for the file command is as below:

file [options] [filename]
  • file – It informs the terminal to run the Linux file command.
  • [options] –Here you can add variables to the command.
  • [filename] – It is the file you want to check by using the command.

After you run the command, the system will auto-reply you, mentioning the type of file in a standard output format.

You will also be provided with other beneficial information, like data stored in the file, the file size or the file version that you have entered.

Here, we created a simple text.txt file. Below is the most basic form of the Linux file command:

file test.txt

The output displays that the file is an ASCII text file.

What to use the Linux File Command for?

With the File command each argument is analyzed for classifying it. Three sets of tests are conducted in this sequence: file system tests, magic tests, and language tests. If the initial analysis succeeds, it provides the file type.

The file system tests are conducted by the users to study the return from a stat system call. The program checks if the file is clear, or if it’s some kind of special type of file. It checks for file types that are known, relevant to the system you are working on, if those are specified by the system in the system header file.

Files with data fixed arrangements are controlled with the application of magic tests. Usually a database is used to manage the probing of lead bytes by the file command. A file termed as magic is where that database is implemented and it is located in devisers/file/magic or a similar one. These files comprise of a magic number saved in a particular place near the start of the file that displays Linux and other operating systems that the file is a binary executable.

After determining the character set, it will then try to specify the language in which the file is written. The language tests find for special sequences that can display from anywhere in the first few segments of a file. These tests are not completely positive as compared to the previous two groups, so these are performed later.

Using the Linux File Command with Options

Since the filenames in UNIX don’t have any connection with their file type, the file command seems to be valuable.

Therefore, a file termed as devisers.csv could be a zip file. You can test this with the below command:

file devisers.csv

In case you just want to view the file type then use the –b option in the terminal along with the filename:

file –b devisers.txt

The file command has the ability to work on multiple files available in the system and return the output in separate lines for each file. For this, you only need to replace a variable with a wildcard – *:

file *.txt

The information will be displayed on all .txt files in the current directory.

You can view the mime type of the file which is not in a readable format with the –i option. The command would appear as below:

file –i devisers.csv

To see the special files, use –s with which the user can read the argument files which are not working or contain special characters. The information about the size of the special files is also specified. You can view the special file with the below command:

file –s txt.t

Make sure to add the name of the actual file you want to inspect!


From the article, it’s clear that the Linux file command is a useful utility for generating long algorithms in various ways according to your needs. You simply need to specify the file and use the command in the correct syntax.

You can understand the things you have on your machine in a precise manner with this command.

After you get used to, to this command, you will learn more about different file types present in your system. This will successfully improve your project. Happy developing!

Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna