File (command)

File is a traditional Unix command for identifying the type or MIME type of a file.

History

The first version of file dates back to 1973, Unix Research Version 4 System V already included a much improved version of file, since this version of the information about the file types were not compiled directly into the executable, but from an external text file ( mime magic file ) is read at runtime.

Today's most popular Unix derivatives, that is primarily BSD and Linux, using a free, open - source implementation, that has been rewritten by Ian Darwin. This implementation was developed in 1989 by Geoff Collyer and received since then a variety of improvements, including from the famous open source hackers like Guy Harris, Chris Lowth and Eric Fischer. The current maintainer is Christos Zoulas.

Specification

The Single Unix Specification (SUS ) provides that an implementation of the program must file a pre-defined set of tests on the file specified on the command line to perform in order to determine their type:

  • If the file can not be read ( for example, due to missing file permissions or because it does not exist ), its type can not be determined ( undefined). file outputs that the file could not be read.
  • File is based on a "stat ()" fixed system call, the file type is. On Unix, there are still files other than normal directories, FIFOs, sockets, block files ( block special) and character files ( character special ).
  • Empty files are detected as such (for example, files that have been created by touch without content, or typically lock files ).
  • File reads the first byte or the whole file and attempts to determine file type-specific pattern to bring in this way the file type to experience.
  • If none of the methods has led to a determination of the file type, the file as an unknown file (data) is called.

In modern implementations of file are in the tests, in which parts of the file are read in, made ​​a comparison with a text database that contains magic numbers. This file is different from much more primitive type of file identifiers, eg based on file extension or MIME type information.

In most implementations used a database file to which it matches the first byte of a file. This database is usually used in a so-called magic- file (English, sorcery ) is stored, which in the file system under / etc / magic, / usr / share / file / magic etc. is typically stored. The extent of this file is usually decisive for the quality of the file- tests to determine also exotic file types.

Use

File can be, like most Unix commands, use virtually intuitive. A call goes according to the scheme

File [ options] file One of the Single Unix Specification compliant implementation of file must be able to handle at least the following arguments:

Examples

The following examples show the typical editions of file when invoking the program with various file types. The file names are fictitious in this case correspond to the native file type. The # sign is to indicate that this line must be entered in a shell.

# File file.c file.c: C program text # File program program: ELF 32 -bit LSB executable, Intel 80386, version 1 ( SYSV ), dynamically linked      ( uses shared libs ), stripped # File / dev/wd0a / dev/wd0a: block special ( 0/0) # File -s / dev/hda1 / dev/hda1: Linux/i386 ext2 filesystem # File -s / dev/hda5 / dev/hda5: Linux/i386 swap file # File compressed.gz compressed.gz: gzip compressed data, deflated, original filename, ' compressed ', last      modified: Thu January 26 14:08:23 2006, os: Unix # File data.ppm data.ppm: Netpbm PPM " rawbits " imagedata see also

  • Binfmt misc: A Linux kernel module, which tries to detect as file based on the first byte of files ( magic numbers ) file types, thus recognizing programs and executes it.
333993
de