( June 15, 2020 )
|operating system||unixoid system|
|License||2-clause BSD license|
The first version of file dates back to 1973, Unix Research Version 4 . System V already contained a much improved version of file , since this version the information about the file types was no longer compiled directly into the program file, but read from an external text file ( mime magic file ) at runtime .
The nowadays common Unix derivatives, that is especially BSD and Linux , use a free open source - Implementation , by Ian Darwin has been rewritten. This implementation was further developed by Geoff Collyer in 1989 and has since received various improvements, including from famous open source hackers such as Guy Harris , Chris Lowth and Eric Fischer . The current supervisor is Christos Zoulas.
The Single UNIX Specification (SUS) provides that an implementation of the program file a clearly defined series of tests with the specified on the command line file must perform in order to determine their type:
- if the file cannot be read (for example due to a lack of file rights or because it does not exist), its type cannot be determined (undefined). file reports that the file could not be read.
file is based on a
stat()- system call determines what type of file it is. In addition to normal files, Unix also has directories , FIFOs , sockets , block files ( block special ) and character files ( character special ).
- Empty files are identified as such (for example, files created by
touchwith no content, or typically lock files ).
- file reads in the first bytes or the entire file and tries to determine file type-specific patterns in order to find out the file type in this way.
- If none of the methods resulted in a determination of the file type, the file is referred to as an unknown file (data) .
In contemporary implementations of file , tests that read parts of the file make comparisons with a text database that contains magic numbers . This distinguishes file from much more primitive file type identifiers, e.g. B. using file extensions or MIME type specifications.
In most implementations, file uses a database against which it compares the first few bytes of a file. This database is typically used in a so-called magic (file engl. , Magical) is stored, which is typically in the file system under
/usr/share/file/magicis stored o. Ä.. The size of this file is usually decisive for the quality of the file tests for determining even exotic file types.
file , like most Unix commands, can be used almost intuitively. A call runs according to the scheme
file [Optionen] Datei
An implementation of file that conforms to the Single UNIX Specification must be able to process at least the following arguments:
||Specify your own “magic” file to be used to determine the file type. The tests normally performed are skipped.|
||Works the same as , except the other tests are done too.
||Report the potential use of softlinks .|
||Classifies the file into one of the following groups: nonexistent, directory , FIFO , socket , block special , character special , symbolic link , regular file, empty file, unreadable file, executable , ar archive , extended cpio format , extended tar format , shell script , C programming language source , FORTRAN programming language source , data file|
The following examples show the typical output of file when the program is called with various file types. The fictitious file names should correspond to your own file type. The pound # is intended 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 Jan 26 14:08:23 2006, os: Unix # file data.ppm data.ppm: Netpbm PPM "rawbits" image data
- binfmt misc : A Linux - kernel module , which as file based on the first bytes of files ( magic numbers ) file types will attempt to detect and recognize programs and executes.
file: determine file type - Open Group Base Specification
- POSIX function call
file(1)- OpenBSD General Commands Manual
file(1)- Debian GNU / Linux executables or shell commands man page
Source code of
- Release 5.39 . June 15, 2020 (accessed June 15, 2020).
- The file Open Source Project on Open Hub: Languages Page . In: Open Hub . (accessed on July 17, 2018).