The file command originated in Unix Research Version 41 in 1973. System V 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 distributions include a free, open-source implementation that was written from scratch by Ian Darwin in 1986–87.2 It keeps file type information in a text file with a format based on that of the System V version. It was expanded by Geoff Collyer 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 system has its own subset implementation written from scratch, but still uses the Darwin/Zoulas collection of magic file formatted information.
The file command was ported to the IBM i operating system.3
As of version 4.00 of the Ian Darwin/Christos Zoulas implementation of file, the functionality of the command is implemented in and exposed by library libmagic that is accessible to consuming code via C (and compatible) linking.4567
SUS8 mandates the following command-line options:
Implementations may add extra options. Ian Darwin's implementation adds -s 'special files', -k 'keep-going' or -r 'raw', among many others.11
For a C source code file, file main.c reports:
For a compiled executable, file program reports information like:
For a block device /dev/hda, file /dev/hda1 reports:
By default, file does not try to read a device file due to potential undesirable effects. But using the non-standard option -s (available in the Ian Darwin branch), which requests to read device files to identify content, file -s /dev/hda1 reports details such as:
Via Ian Darwin's non-standard option -k, the command 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 new line character to be displayed in its raw form rather than in its octal representation. On Linux, file -k -r libmagic-dev_5.35-4_armhf.deb reports information like:
For a compressed file, file compressed.gz reports information like:
For a compressed file, file -i compressed.gz reports information like:
For a PPM file, file data.ppm reports;
For a Mach-O universal binary, file /bin/cat reports like:
For a symbolic link, file /usr/bin/vi reports:
Identifying a symbolic link is not available on all platforms and will be dereferenced if -L is passed or POSIXLY_CORRECT is set.
"Source of the UNIX V4 "file" man page". Archived from the original on 2019-12-10. Retrieved 2022-03-13. https://minnie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man1/file.1 ↩
The early history of this program is recorded in its private CVS repository; see [1] Archived 2017-04-01 at the Wayback Machine the log of the main program https://www.darwinsys.com/file/file.c.log.txt ↩
"IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Archived (PDF) from the original on 2021-03-05. Retrieved 2020-09-05. https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc ↩
libmagic(3) – Linux Programmer's Manual – Library Functions https://manned.org/libmagic.3 ↩
libmagic(3) – NetBSD Library Functions Manual https://man.netbsd.org/libmagic.3 ↩
Zoulas, Christos (February 27, 2003). "file-3.41 is now available". File (Mailing list). Archived from the original on March 4, 2016. Retrieved January 1, 2013. https://mx.gw.com/pipermail/file/2003/000034.html ↩
Zoulas, Christos (March 24, 2003). "file-4.00 is now available". File (Mailing list). Archived from the original on December 28, 2016. Retrieved January 1, 2013. https://mx.gw.com/pipermail/file/2003/000043.html ↩
"The Open Group Base Specifications Issue 7 — file command". Archived from the original on 2018-10-12. Retrieved 2014-08-20. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html ↩
file(1) – Linux User Manual – User Commands https://manned.org/file.1 ↩
file(1) – NetBSD General Commands Manual https://man.netbsd.org/file.1 ↩