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.
file Documents/ Documents/: directory file high-tech-stats.pdf high-tech-stats.pdf: PDF document, version 1.2 file Nari-288.rm Nari-288.rm: RealMedia file file bijlage10.sdw bijlage10.sdw: Microsoft Office Document file logo.xcf logo.xcf: GIMP XCF image data, version 0, 150 x 38, RGB Color file cv.txt cv.txt: ISO-8859 text file image.png image.png: PNG image data, 616 x 862, 8-bit grayscale, non-interlaced file figure figure: ASCII text Introduction to Linux Chapter 3. About files and the file system 49 file me+tux.jpg me+tux.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), "28 Jun 1999", 144 x 144 file 42.zip.gz 42.zip.gz: gzip compressed data, deflated, original filename, `42.zip', last modified: Thu Nov 1 23:45:39 2001, os: Unix file vi.gif vi.gif: GIF image data, version 89a, 88 x 31 file slide1 slide1: HTML document text file template.xls template.xls: Microsoft Office Document file abook.ps abook.ps: PostScript document text conforming at level 2.0 file /dev/log /dev/log: socket file /dev/hda /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.