File (command)
   HOME

TheInfoList



OR:

The file
command Command may refer to: Computing * Command (computing), a statement in a computer language * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on Apple Macintosh computer keyboards * ...
is a standard
program Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Programm ...
of
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, ...
and
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
operating systems An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
for recognizing the type of data contained in a
computer file A computer file is a computer resource for recording data in a computer storage device, primarily identified by its file name. Just as words can be written to paper, so can data be written to a computer file. Files can be shared with and trans ...
.


History

The original version of file originated in Unix Research Version 4 in 1973.
System V Unix System V (pronounced: "System Five") is one of the first commercial versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V were released, numbered 1, 2, 3, an ...
brought a major update with several important changes, most notably moving the file type information into an external text file rather than compiling it into the binary itself. Most major BSD and
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, whi ...
distributions use a free,
open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized so ...
reimplementation which was written in 1986–87 by Ian Darwin from scratch. It was expanded by
Geoff Collyer Geoff Collyer (born 1958) is a Canadian computer scientist. He is the senior author of ''C News'', a protocol-neutral news transport, and the designer of NOV, the News Overview database (article index) used by all modern newsreaders. He contrib ...
in 1989 and since then has had input from many others, including Guy Harris, Chris Lowth and Eric Fischer; from late 1993 onward its maintenance has been organized by Christos Zoulas. The
OpenBSD OpenBSD is a security-focused, free and open-source, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by forking NetBSD 1.0. According to the website, the OpenBSD project e ...
system has its own subset implementation written from scratch, but still uses the Darwin/Zoulas collection of magic file formatted information. The command has also been ported to the
IBM i IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS i ...
operating system.


Specification

The Single UNIX Specification (SUS) specifies that a series of tests are performed on the file specified on the command line: # if the file cannot be read, or its Unix file type is undetermined, the file program will indicate that the file was processed but its type was undetermined. # file must be able to determine the types
directory Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network' ...
, FIFO,
socket Socket may refer to: Mechanics * Socket wrench, a type of wrench that uses separate, removable sockets to fit different sizes of nuts and bolts * Socket head screw, a screw (or bolt) with a cylindrical head containing a socket into which the hexag ...
, block
special file In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files ...
, and character special file # zero-length files are identified as such # an initial part of file is considered and file is to use position-sensitive tests # the entire file is considered and file is to use context-sensitive tests # the file is identified as a data file file's position-sensitive tests are normally implemented by matching various locations within the file against a textual database of magic numbers (see the Usage section). This differs from other simpler methods such as file extensions and schemes like
MIME Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of email messages to support text in character sets other than ASCII, as well as attachments of audio, video, images, and application programs. Message ...
. In most implementations, the file command uses a database to drive the probing of the lead bytes. That database is implemented in a file called magic, whose location is usually in /etc/magic, /usr/share/file/magic or a similar location.


Usage

The SUS mandates the following options: : -M ''file'', specify a file specially formatted containing position-sensitive tests; default position-sensitive tests and context-sensitive tests will not be performed. : -m ''file'', as for -M, but default tests will be performed after the tests contained in file. : -d, perform default position-sensitive and context-sensitive tests to the given file; this is the default behaviour unless -M or -m is specified. : -h, do not dereference symbolic links that point to an existing file or directory. : -L, dereference the symbolic link that points to an existing file or directory. : -i, do not classify the file further than to identify it as either: nonexistent, a block special file, a character special file, a directory, a FIFO, a socket, a symbolic link, or a regular file. Linux and BSD systems behave differently with this option and instead output an
Internet media type A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication o ...
("
MIME Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of email messages to support text in character sets other than ASCII, as well as attachments of audio, video, images, and application programs. Message ...
type") identifying the recognized file format. Other
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, ...
and
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
operating systems may add extra options than these, such as -s 'special files', -k 'keep-going' or -r 'raw' (examples below). The command tells only what the file ''looks like'', not what it is (in the case where ''file'' looks at the content). It is easy to fool the program by putting a magic number into a file the content of which does not match it. Thus the command is not usable as a security tool other than in specific situations.


Examples

$ file file.c file.c: C program text $ file program program: ELF
32-bit In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in 32- bit units. Compared to smaller bit widths, 32-bit computers can perform large calculati ...
LSB
executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instructions", as opposed to a data fil ...
, Intel 80386, version 1 ( SYSV), dynamically linked (uses shared libs), stripped $ file /dev/hda1 /dev/hda1: block special (0/0) $ file -s /dev/hda1 /dev/hda1: Linux/
i386 The Intel 386, originally released as 80386 and later renamed i386, is a 32-bit microprocessor introduced in 1985. The first versions had 275,000 transistorsext2 filesystem Note that -s is a non-standard option available only on some platforms, which tells file to read device files and try to identify their contents rather than merely identifying them as device files. Normally file does not try to read device files since reading such a file can have undesirable side effects. $ file -k -r libmagic-dev_5.35-4_armhf.deb # (on Linux) libmagic-dev_5.35-4_ armhf. deb: Debian binary package (format 2.0) - current ar archive - data Through the non-standard option -k the program does not stop after the first hit found, but looks for other matching patterns. The -r option, which is available in some versions, causes the unprintable
new line New is an adjective referring to something recently made, discovered, or created. New or NEW may refer to: Music * New, singer of K-pop group The Boyz Albums and EPs * ''New'' (album), by Paul McCartney, 2013 * ''New'' (EP), by Regurgitator, ...
character to be displayed in its raw form rather than in its octal representation. $ file compressed.gz compressed.gz: gzip compressed data, deflated, original filename, `compressed', last modified: Thu Jan 26 14:08:23 2006, os: Unix $ file -i compressed.gz # (on Linux) compressed.gz: application/x-gzip;
charset Character encoding is the process of assigning numbers to graphical characters, especially the written characters of human language, allowing them to be stored, transmitted, and transformed using digital computers. The numerical values tha ...
= binary $ file data.ppm data.ppm: Netpbm PPM "rawbits" image data $ file /bin/cat /bin/cat:
Mach-O Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. It was developed to replace the a.out format. Mach-O is used by some systems based on the Mac ...
universal binary with 2 architectures /bin/cat (for architecture ppc7400): Mach-O executable ppc /bin/cat (for architecture i386): Mach-O executable i386 $ file /usr/bin/vi /usr/bin/vi: symbolic link to vim Identifying symbolic links is not available on all platforms and will be dereferenced if -L is passed or POSIXLY_CORRECT is set.


Libmagic library

As of version 4.00 of the Ian Darwin/Christos Zoulas version of file, the functionality of file is incorporated into a libmagic
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
that is accessible via C (and C-compatible) linking; file is implemented using that library.


References


External links

*
file mailing list

file releases


Manual pages

* * * * *


Other


Fine Free File Command
– homepage for version of file used in major BSD and Linux distributions.

– webpage of native
GnuWin32 The G''nu''W''in''32 project provides native ports in the form of executable computer programs, patches, and source code for various GNU and open source tools and software, much of it modified to run on the 32-bit Windows platform. The ports inc ...
port of file for 32 bit Windows. * Th
libmagic-dev package
o
packages.debian.org


an alternative providing ranked answers (instead of just one) based on statistics. {{DEFAULTSORT:File (Command) Standard Unix programs Unix SUS2008 utilities Plan 9 commands IBM i Qshell commands