[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedJune 22, 2023

How to use file comand.

How To Use File Comand.

The file command displays the type of a file.

 

Linux File Command Syntax

The syntax for the Linux file command is as follows:

file [OPTION] [FILE]

It can take one or more file names as its arguments.

 

How to Use the file Command to Find the File Type

The file command classifies files based on a series of tests and determines the file type based on the first successful test.

In its simplest form when used without any option, the file command will display the file name along with the file type:

file /etc/group
/etc/group: ASCII text

To show just the file type use the -b (–brief) option:

file -b /etc/group
ASCII text

As you can see from the output above the /etc/group file is a text file.

 

How to Find the File Type of Multiple Files

You can pass more than one files to the file command:

file /bin/bash /opt/card.zip

The command will print the type of each file on a separate file:

/bin/bash:     ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=42602c973215ba5b8ab5159c527e72f38e83ee52, stripped
/opt/card.zip: Zip archive data, at least v1.0 to extract

It also accepts wildcard characters. For example, to find the type of each .jpg files in the current directory you would run:

file *.jpg
imgage001.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive, precision 8, 2083x1250, components 3
mgage031.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, comment: "Created with GIMP", baseline, precision 8, 1280x1024, components 

How to View the Mime Type of a File

Use the -i (–mime) option to determine the mime type of a file:

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

 

Conclusion

By now you should have a good understanding of how to use the Linux file command.

Keep reading
How to Install and Use Curl on Debian 10
March 16, 2023

How to Install and Use Curl on Debian 10

How To Install And Use Curl On Debian 10 This guide explains how to install and use the curl command on Debian 10, Buster. If you are trying to download a file using curl and getting an error message saying curl command not found it simply means that the curl package is not installed on…

Read article
How to Truncate (Empty) Files in Linux
March 16, 2023

How to Truncate (Empty) Files in Linux

How To Truncate (Empty) Files In Linux This tutorial explains how to truncate files to zero size in Linux systems using shell redirection and the truncate command. In some situations, you might want to truncate (empty) an existing file to a zero-length. In simple words, truncating a file means…

Read article
How to use pushd & podp command.
March 15, 2023

How to use pushd & podp command.

How To Use Pushd & Podp Command. In this tutorial, we will show you how to use the pushd and popd commands to navigate your system’s directory tree. pushd and popd are commands that allow you to work with directory stack and change the current working directory in Linux and other Unix-like…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00