Linux File Command
2 min read
file command displays the type of a file. It’s helpful when you have to find out the type of file you’ve never seen before or the file does not have a file extension.
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
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:
/etc/group: ASCII text
To show just the file type use the
file -b /etc/group
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 /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:
imgage001.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive, precision 8, 2083x1250, components 3 imgage031.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
--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. For more information about the
find command, see the file man page .