file: file is a command that will identify the type of file – executable, text or data. If the file is one of well-known formats like zip, tar, pdf then it says so.
eg. $ file *
tamil-keyboard-color.jpg: JPEG image data, JFIF standard 1.01
tamil-keyboard-unicode.png: PNG image, 815 x 436, 8-bit/color RGB, non-interlaced
targets: ASCII text
testprint.txt: ASCII text
test.xls: Microsoft Office Document
thinclient_lts.conf: ASCII English text
upgradehims.odt: OpenDocument Text
w2008.sxw: OpenOffice.org 1.x Writer document
w2009.odt: OpenDocument Text
file looks into content and don’t determine based on file extension. Normally every type of file like pdf, odt have some specific signature at specific offset – called magic. file looks for this magic and determines nature of file. file can also determine the programming language in case of programmes like – shell script, perl script based on hashbang #!. The magic number details are stored in /usr/share/file/magic (in debian)
file is very useful in several situations. Normally whenever there is a filesystem corruption and fsck is run, many files are recovered and kept under lost+found directory. These recovered files will have names which are normally the inode numbers and not the original name. Thus no extensions or names to guess what it contains. Using file command on such file will give us the type of file. Probably we can rename with appropriate extension.