Share to: share facebook share twitter share wa share telegram print page

File (command)

file
Developer(s)AT&T Bell Laboratories
Initial release1973 (1973) as part of Unix Research Version 4; 1986 (1986) open-source reimplementation
Repositorygithub.com/file/file
Written inC
Operating systemUnix, Unix-like, Plan 9, IBM i
PlatformCross-platform
TypeFile type detector
LicenseBSD license, CDDL
Plan 9: MIT License
Websitedarwinsys.com/file/

The file command is a standard program of Unix and Unix-like operating systems for recognizing the type of data contained in a computer file.

History

The original version of file originated in Unix Research Version 4[1] 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 use a free, open-source reimplementation which was written in 1986–87 by Ian Darwin[2] from scratch; 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 has also been ported to the IBM i operating system.[3]

Specification

The Single UNIX Specification (SUS) specifies that a series of tests are performed on the file specified on the command line:

  1. 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.
  2. file must be able to determine the types directory, FIFO, socket, block special file, and character special file
  3. zero-length files are identified as such
  4. an initial part of file is considered and file is to use position-sensitive tests
  5. the entire file is considered and file is to use context-sensitive tests
  6. 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.

In the System V implementation, the Ian Darwin implementation, and the OpenBSD implementation, 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[4] 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[5] and BSD[6] systems behave differently with this option and instead output an Internet media type ("MIME type") identifying the recognized file format.

Other Unix and Unix-like operating systems may add extra options than these. Ian Darwin's implementation adds -s 'special files', -k 'keep-going' or -r 'raw' (examples below), among many others.[5]

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 LSB executable, 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 ext2 filesystem

Note that -s is a non-standard option available only on the Ian Darwin branch, 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 Ian Darwin's 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 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=binary
$ file data.ppm
data.ppm: Netpbm PPM "rawbits" image data
$ file /bin/cat
/bin/cat: Mach-O 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 that is accessible via C (and C-compatible) linking;[7][8] file is implemented using that library.[9][10]

References

  1. ^ "Source of the UNIX V4 "file" man page". Archived from the original on 2019-12-10. Retrieved 2022-03-13.
  2. ^ 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
  3. ^ "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Archived (PDF) from the original on 2021-03-05. Retrieved 2020-09-05.
  4. ^ "The Open Group Base Specifications Issue 7 — file command". Archived from the original on 2018-10-12. Retrieved 2014-08-20.
  5. ^ a b file(1) – Linux User Manual – User Commands
  6. ^ file(1) – NetBSD General Commands Manual
  7. ^ libmagic(3) – Linux Programmer's Manual – Library Functions
  8. ^ libmagic(3) – NetBSD Library Functions Manual
  9. ^ 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.
  10. ^ 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.

Manual pages

Other

  • Fine Free File Command – homepage for Ian Darwin's version of file used in major BSD and Linux distributions.
  • binwalk, a firmware analysis tool that carves files based on libmagic signatures
  • TrID, an alternative providing ranked answers (instead of just one) based on statistics.

Read other articles:

اشتباكات جنوب لبنان في سبتمبر 1992جزء من الصراع في جنوب لبنان (1982-2000)التاريخ30 سبتمبر 1992الموقعجنوب لبنانالنتيجةصد هجوم حزب الله على موقع جيش لبنان الجنوبيالمتحاربونجيش لبنان الجنوبي حزب اللهالإصابات والخسائر9 قتلى، من بينهم فرد من حفظة السلام التابعين لليونيفيل عنتصندوق ا...

Measurement tool For the plant sometimes called the Jacob's staff, see Ocotillo. Jacob's staff in the Museo Galileo, Florence Measuring the height of a star with a Jacob's staff The term Jacob's staff is used to refer to several things, also known as cross-staff, a ballastella, a fore-staff, a ballestilla, or a balestilha. In its most basic form, a Jacob's staff is a stick or pole with length markings; most staffs are much more complicated than that, and usually contain a number of measuremen...

この記事は検証可能な参考文献や出典が全く示されていないか、不十分です。出典を追加して記事の信頼性向上にご協力ください。(このテンプレートの使い方)出典検索?: 西尾市立三和小学校 – ニュース · 書籍 · スカラー · CiNii · J-STAGE · NDL · dlib.jp · ジャパンサーチ · TWL(2015年1月) 西尾立三和小学校 北緯34度52分49.6秒 東

NGC 6271   الكوكبة الجاثي  رمز الفهرس NGC 6271 (الفهرس العام الجديد)PGC 59365 (فهرس المجرات الرئيسية)2MASX J16585070+2757542 (Two Micron All Sky Survey, Extended source catalogue)MCG+05-40-016 (فهرس المجرات الموروفولوجي)UZC J165850.8+275754 (فهرس زفيكي المحدّث)Z 1656.8+2803 (فهرس المجرات وعناقيد المجرات)Z 169-21 (فهرس المجرات وعناقيد المجر...

  لمعانٍ أخرى، طالع السيح (توضيح). هذه مقالة غير مراجعة. ينبغي أن يزال هذا القالب بعد أن يراجعها محرر مغاير للذي أنشأها؛ إذا لزم الأمر فيجب أن توسم المقالة بقوالب الصيانة المناسبة. يمكن أيضاً تقديم طلب لمراجعة المقالة في الصفحة المخصصة لذلك. (أغسطس 2023) السيح مركز موقع مح...

Carlos P. GarciaPresiden Filipina ke-8 Presiden ke-4 dari Republik ke-3Masa jabatan18 Maret 1957 – 30 Desember 1961Wakil PresidenDiosdado Macapagal (1957-1961)PendahuluRamon MagsaysayPenggantiDiosdado MacapagalWakil Presiden Filipina ke-4 Wakil Presiden ke-3 dari Republik ke-3Masa jabatan30 Desember 1953 – 17 Maret 1957PresidenRamon MagsaysayPendahuluFernando LopezPenggantiDiosdado Macapagal Informasi pribadiLahir(1896-11-04)4 November 1896Talibon, BoholMeninggal14 Juni ...

2017 studio album by Marty Stuart & His Fabulous SuperlativesWay Out WestStudio album by Marty Stuart & His Fabulous SuperlativesReleasedMarch 10, 2017LanguageEnglishLabelSuperlatoneProducerMike Campbell[1]Marty Stuart chronology Saturday Night / Sunday Morning(2014) Way Out West(2017) Way Out West is American country singer Marty Stuart's 18th studio album released in 2017.[2] The album was produced by Tom Petty and the Heartbreakers guitarist Mike Campbell. T...

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada.Este aviso fue puesto el 21 de diciembre de 2017. Reconquista Localidad y municipio BanderaEscudo ReconquistaLocalización de Reconquista en Provincia de Santa Fe ReconquistaLocalización de Reconquista en ArgentinaCoordenadas 29°08′40″S 59°38′38″O / -29.1443478, -59.6437728Entidad Localidad y municipio • País  Argentina • Provincia  Santa Fe • ...

Bagian dari seri tentangAgama Buddha Sejarah dan PenyebaranGaris waktu • Sidang agung • Asia Tenggara • Asia Timur • Tibet • Asia Tengah • Indonesia • Dunia Barat AliranTheravāda • Mahāyāna • Vajrāyāna • Sthaviravāda • Mahāsāṃghika Konsep UtamaTiga Permata • Ketuhanan • Lima Hukum Alam • Puasa • Saṃsāra • Tiga Corak Umum • Lima Agregat • Hukum Sebab Musaba...

Israel's competition at the 1976 Summer Olympics Sporting event delegationIsrael at the1976 Summer OlympicsIOC codeISRNOCOlympic Committee of IsraelWebsitewww.olympicsil.co.il (in Hebrew and English)in MontrealCompetitors26 in 10 sportsFlag bearer Esther Roth-Shachamarov[1]Medals Gold 0 Silver 0 Bronze 0 Total 0 Summer Olympics appearances (overview)1952195619601964196819721976198019841988199219962000200420082012201620202024 Israel competed at the 1976 Summer Olympics in Mon...

This is a list of University of Salford people, including staff (past and present) and alumni from the University of Salford. Notable staff Allan Boardman Allan Boardman: Physics Ralph Darlington: Employment Relations Trevor Cox: Acoustic Engineering Garry Crawford: Cultural Sociology Said Faiq: Translation & Interpreting Neal Hazel: Criminology and Criminal Justice Andy Miah: Science Communication and Future Media Miklas Scholz: Water resources engineering Audrey Stuckes: Material scienc...

Group of three muscles which make up the buttocks This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (October 2016) (Learn how and when to remove this template message) Gluteal musclesRight leg, rear view: Muscles of the gluteal and posterior femoral regions. Gluteus minimus and the origins and insertions of medius and maximus shown in red.Gluteus maximusDetailsP...

1998 video gameWetrixNorth American Nintendo 64 cover artDeveloper(s)Zed TwoPublisher(s)N64, WindowsOcean SoftwareDreamcastNA: Xicat InteractiveEU: Take-Two Interactive Game Boy ColorJP: ImagineerEU: Infogrames EuropeDesigner(s)Ste and John PickfordProgrammer(s)John PickfordArtist(s)Ste PickfordComposer(s)Suddi RavalMartin GoodallKeith TinmanPlatform(s)Nintendo 64, Windows, Game Boy Color, DreamcastReleaseNintendo 64EU: May 1998NA: 16 June 1998WindowsWW: 15 January 1999Game Boy ColorJP: Octob...

Disney cartoon characters This article is about the characters. For the film, see Chip an' Dale. For other uses, see Chip 'n Dale: Rescue Rangers and Chippendale. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Chip 'n' Dale – news · newspapers · books · scholar · JSTOR (September 2021) (Learn how and when t...

PertaruhanPoster resmiSutradara Krishto Damar Alam Produser Adianto Sumardjono Ditulis oleh Upi Avianto PemeranAdipati DolkenAliando SyariefTio PakusadewoJefri NicholGiulio ParengkuanWidika SidmoreTarzanSilvia AnggrainiPerusahaanproduksiIFI SinemaTanggal rilis 9 Februari 2017Negara IndonesiaBahasa Indonesia Pertaruhan merupakan film laga Indonesia yang dirilis pada 9 Februari 2017 yang diproduksi oleh IFI Sinema, disutradarai oleh Krishto Damar Alam serta dibintangi oleh Adipati Dolken, Alian...

Struggle of a religious kind in Islam For other uses, see Jihad (disambiguation). Part of a series onIslamic jurisprudence(fiqh) Ritual Shahada Salah Raka'ah Qibla Turbah Sunnah prayer (TahajjudTarawih) Witr Nafl prayer Sawm Zakat Hajj Ihram (clothing Mut'ah) Tawaf Umrah (and Hajj) Political Islamic leadership Caliphate Majlis-ash-Shura Imamate Wilayat al-faqih Bay'ah Dhimmi Aman Family Marriage Contract Mahr Misyar Halala Urfi Mut‘ah Polygyny Divorce Khula Zihar Iddah Kafa'ah Ado...

Ця стаття потребує істотної переробки. Можливо, її необхідно доповнити, переписати або вікіфікувати. Пояснення причин та обговорення — на сторінці Вікіпедія: Статті, що необхідно поліпшити. Тому, хто додав шаблон: зважте на те, щоб повідомити основних авторів статті п...

Municipal building in Sandwich, Kent, England Sandwich GuildhallSandwich GuildhallLocationCattle Market, SandwichCoordinates51°16′29″N 1°20′19″E / 51.2748°N 1.3387°E / 51.2748; 1.3387Built1579Architectural style(s)Medieval style Listed Building – Grade II*Official nameThe GuildhallDesignated19 May 1950Reference no.1069731 Shown in Kent Sandwich Guildhall is a municipal building in the Cattle Market, Sandwich, Kent, England. The structure, which accom...

Dutch former professional footballer (born 1963) Adick Koot Personal informationDate of birth (1963-08-16) 16 August 1963 (age 60)Place of birth Eindhoven, NetherlandsHeight 1.85 m (6 ft 1 in)Position(s) Centre backYouth career UDI'19Senior career*Years Team Apps (Gls)1983–1991 PSV 111 (3)1991–1998 Cannes 194 (5)1998–1999 Lille 26 (2)Total 331 (10)International career1988–1989 Netherlands 3 (0)Managerial career1997–1998 Cannes *Club domestic league appearances an...

American TV series or program The Generations ProjectGenreRealityDirected byTyler WestonPresented byLise SimmsNarrated byLise SimmsComposerMicah Dahl AndersonCountry of originUnited StatesOriginal languageEnglishNo. of seasons3No. of episodes38ProductionExecutive producersKendall WilcoxAndra Johnson DukeProducersMarissa BernhardRaquel MarvezAgustina PerezJosh WagnerCinematographyTy ArnoldBrandon ChristensenTravis ClineCole WebleyEditorsIrina ClineJared CookShark J. GillinsAndrew JamesQ. ...

Kembali kehalaman sebelumnya