[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
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 Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

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

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

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM