file – command displays the type of data file based on rules defined in the file /usr/lib/magic (known as the magicfile).
file [options] files
-c displays formatted in a specified magic file (or file by default) and exits.
-m file1 [: file2: … ] Indicates that other magic files.
-z scans compressed files.
To determine the type of data in these files, the file command uses the rules specified in the file /usr/lib/magic. For example, using the command file you check the type of each file in the directory /usr/lib as follows: file * | more
To find out more about the kind of data we are dealing with, we use the file command. By applying certain tests that check properties of a file in the file system, magic numbers and language tests, file tries to make an educated guess about the format of a file.
high-tech-stats.pdf: PDF document, version 1.2
Nari-288.rm: RealMedia file
bijlage10.sdw: Microsoft Office Document
logo.xcf: GIMP XCF image data, version 0, 150 x 38, RGB Color
cv.txt: ISO-8859 text
image.png: PNG image data, 616 x 862, 8-bit grayscale, non-interlaced
figure: ASCII text
Introduction to Linux
Chapter 3. About files and the file system 49
me+tux.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI),
"28 Jun 1999", 144 x 144
42.zip.gz: gzip compressed data, deflated, original filename,
`42.zip', last modified: Thu Nov 1 23:45:39 2001, os: Unix
vi.gif: GIF image data, version 89a, 88 x 31
slide1: HTML document text
template.xls: Microsoft Office Document
abook.ps: PostScript document text conforming at level 2.0
/dev/hda: block special (3/0)
The file command has a series of options, among others the -z option to look into compressed files. See info file for a detailed description. Keep in mind that the results of file are not absolute, it is only a guess. In other words, file can be tricked.