Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
The file command displays the type of a file.
The syntax for the Linux file command is as follows:
file [OPTION] [FILE]
It can take one or more file names as its arguments.
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.
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
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
By now you should have a good understanding of how to use the Linux file command.