[Ilugc] One Day One GNU/Linux Command (FILE)

  • From: sbharathi@xxxxxxxxxxxxx (Bharathi Subramanian)
  • Date: Thu Aug 21 09:50:20 2008

One Day One GNU/Linux Command
=============================

file -- Try to determine the FILE type.

Summary:

File tests each argument in an attempt to classify it. There are 3
sets of tests, performed in this order: File System Test, Magic 
Number Test, and Language Test.

File System test will examine the return value of the stat(2) system
call, to see if the file is empty, or a special file (block, char,
pipe, dir, link, socket,..).

Magic Number test will try to match the file with particular fixed
formats. For example, a binary executable files will have magic number
in some fixed position to indicate the OS, that file is executable.
Few standard data files also following the magic number concept.

Language Test will try to find the file char set like ASCII, UTF-8,
ISO-8859-x, etc,. Once file has determined the character set used in a
text-type file, it will attempt to determine in what (prg) language
the file is written.

Unidentified file will be classified as DATA file.

Example:

$ file myfile -- Print the file type.

$ file -b myfile -- Don't show the filename in the output.

$ file -f list -- Take the input filenames (one per line) from the 
                  file 'list'.

$ file -k myfile -- Print all matches. 

$ file -z myfile.tgz -- Try to look into compressed file.

$ file -i myfile -- Print the output in MIME format.

$ file -m mymagic myfile -- Use custom magic file.

# file -s /dev/hda? -- Take blk/char special files as an argument.

Read: man file

HTH :)
--
Bharathi S

Other related posts:

  • » [Ilugc] One Day One GNU/Linux Command (FILE) - Bharathi Subramanian