fileのヘルプ・マニュアル
日本語 英語
file --help
man file
FILE(1) FILE(1)
名前
file - ファイルタイプを判定する
書式
file [ -bcikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles
] file ...
file -C [ -m magicfile ]
説明
この man ページは file コマンド version 4.12 について記述している。
file は各引き数をテストして分類する。ファイルシステムテスト、マジックナ
ンバーテスト、言語テストの順序で 3 つのテストを行う。そのうちの最初に成
功したテストで、ファイルタイプを表示する。
表示されるタイプには通常以下のうち 1 つの単語が含まれる。 text (この フ
ァ イルには表示可能文字といくつかの一般的な制御文字のみが含まれ、 ASCII
端末で読んでも多分安全である)、 executable (このファイルにはプログラ ム
を コンパイルした結果が含まれ、 UNIX カーネルなどにより実行可能な形式で
ある)、 data その他のもの (data は通常「バイナリ」または表示不能なフ ァ
イルである)。ただしバイナリデータを含んでいる良く知られた形式のフォーマ
ット (core ファイル、tar ア ー カ イ ブ な ど) は 例 外 で あ る 。
/usr/share/file/magic ファイルや file プログラム自身を変更する場合も、
これらのキーワードは変更しないこと。人々は、ディレクトリ内の読み取り 可
能なファイルに対しては、全て ‘‘text’’ が表示されると思っている。 Berke-
ley がかつてやったように、 ‘‘shell commands text’’ を ‘‘shell script’’
に変更したりしてはいけない。ファイル /usr/share/file/magic は、このプロ
グラムのソースディストリビューションのサブディレクトリ Magdir にある 数
多くの小さなファイルから機械的に作られている点に注意すること。
ファイルシステムのテストは、 stat(2) システムコールの結果の検討に基づい
て行われる。このプログラムは、ファイルが空であるかや、特殊ファイルで あ
る かをチェックする。実行中のシステムに特有の既存のファイルタイプ (ソケ
ット・シンボリックリンク・名前付きパイプ (FIFO) (ただしシステムで実装さ
れている場合)) は、システムのヘッダファイル に定義されてい
れば、すぐに分かる。
マジックナンバーテストは、特定の決まった形式のデータを含むファイルを チ
ェ ックするのに使われる。もっとも簡単な例は、バイナリ実行可能ファイル (
コンパイルされたプログラム) a.out である。この形式は標準インクルード デ
ィレクトリの a.out.h で定義されている (exec.h の場合もある)。これらのフ
ァイルにはファイルの先頭付近の特定位置に「マジックナンバー」が格納さ れ
て いる。これにより UNIX オペレーティングシステムは、ファイルがバイナリ
実行可能であることが分かり、そのうちのどのファイルタイプであるかも分 か
る 。「マジックナンバー」の考え方は、データファイルに対する拡張にも応用
されている。ファイルの先頭から近い場所に一定の識別子を持つファイルは 、
通 常はこの方法で記述できる。これらのファイルについての情報識別子は、コ
ンパイルされたマジックファイル /usr/share/file/magic.mgc から読み込まれ
る。このコンパイルされたファイルがない場合は、 /usr/share/file/magic か
ら読み込まれる。更に file は $HOME/.magic.mgc または $HOME/.magic か ら
マジックファイルのエントリを探す。
フ ァイルがマジックファイルのどのエントリともマッチしなかった場合、テキ
ストファイルであるかを調べる。文字集合内の表示可能なテキストを構成す る
バ イト列の範囲の違いを調べることにより、 ASCII, ISO-8859-x, (Macintosh
や IBM PC システムで使用されている) ISO に準拠しない 8 ビット拡張 ASCII
文 字集合、 UTF-8 エンコードされたユニコード、UTF-16 エンコードされたユ
ニコード、 EBCDIC 文字集合を識別する。ファイルがこれらのテストをパス す
る と、文字集合名が表示される。 ASCII, ISO-8859-x, UTF-8, 拡張 ASCII の
ファイルは、これはほぼ全ての端末で読むことができるので、 ‘‘text’’ と し
て 識別される。 UTF-16 と EBCDIC のファイルは、たとえテキストを含んでい
たとしても読む前に変換が必要なので、単なる ‘‘character data’’ とされ る
。 さらに file はテキスト型ファイルの他の特徴も決定しようとする。ファイ
ルの行が Unix で標準的な LF ではなく、 CR, CRLF, NEL で終了している場合
は 、その旨を表示する。ファイルに組み込み (embedded) エスケープシーケン
スや重ね打ち (overstriking) が含まれている場合も、その旨を表示する。
file はテキスト型ファイルで使われている文字集合を決定した後は、ファイル
が 書かれている言語を決定しようとする。言語テストではファイルの最初の数
ブロックのどこかに現れる特定の文字列 (names.h を参照) を探す。例えば キ
ーワード .br があれば、そのファイルは多くの場合 troff(1) の入力ファイル
であることを示しており、キーワード struct は C 言語プログラムであること
を 示している。これらのテストは前のテストに比べると信頼性が低いので、最
後に実行される。言語テストのルーチンは他のファイルタイプ (例えば tar(1)
アーカイブ) に関するテストも行う。
上 に挙げた文字集合のどれにも当てはまらないファイルは、単に ‘‘data’’ と
表示される。
オプション
-b, --brief
出力行の最初にファイル名を表示しない (簡易モード)。
-c, --checking-printout
マジックファイルの解析形式を表示してチェックする。通常は -m オ
プ ションと一緒に用いて、新しいマジックファイルをインストールす
る前のデバッグに使う。
-C, --compile
マジックファイルを事前に解析した内容 を 含 む 出 力 フ ァ イ ル
magic.mgc を書き出す。
-f, --files-from namefile
他 の引き数リストより先に、検査するファイルの名前を namefile フ
ァイルから読み込む (1 行に 1 つのファイル名)。 namefile また は
少なくとも 1 つのファイル名引き数がなければいけない。標準入力を
テストする場合は、ファイル名引き数として ‘‘-’’ を使うこと。
-F, --separator separator
指定した文字列をファイル名とファイルをテストした結果の区切り 文
字とする。デフォルトは ‘‘:’’ である。
-i, --mime
file コマンドの出力を人間が読みやすい昔ながらのものではなく、
mime タイプ文字列にする。したがって ‘‘ASCII text’’ ではな く 、
‘‘text/plain; charset=us-ascii’’ のように出力される。このオプシ
ョンを動作させるため、 file コマンドが認識するファイルの取り 扱
い 方法 (多くのテキストファイルタイプやディレクトリ) を変更し、
別の ‘‘magic’’ ファイルを使うようにした。 (下記の「ファイル」の
セクションを参照)。
-k, --keep-going
最初にマッチしたもので停止せず、次のマッチングに進む。
-L, --dereference
(システムがシンボリックリンクをサポートしている場合は) ls(1) の
同じ名前のオプションと同様に、シンボリックリンクを辿るように さ
せる。
-m, --magic-file list
マジックナンバーが書かれた別のファイルのリストを指定する。 1 つ
のファイルでも、コンマで区切られたファイルのリストでもよい。 コ
ン パイル済みのマジックファイルが一緒に指定された場合は、代りに
それを使う。
-n, --no-buffer
1 つのファイルをチェックする毎に、標準出力をフラッシュする。 こ
れ は複数のファイルをチェックするときにのみ役立つ。このオプショ
ンは、ファイルタイプをパイプから出力するプログラムで使われる こ
と を意図している。 -i または --mime オプションと一緒に指定する
と、このプログラムは各ファイル名の後に ".mime" を追加する。
-N, --no-pad
出力を整列するためのファイル名への空白の追加を行わない。
-p, --preserve-date
utime(2) または utimes(2) をサポートするシステムでは、 file(1)
が 解析したファイルを読み込まれなかったかのようにするため、アク
セス時刻を保存しようとする。
-r, --raw
印字不能文字を \ooo に変換しない。通常、 file は印字不能文字 を
8 進数表現に変換する。
-s, --special-files
通常 file は、引き数で指定されたファイルのうち stat(2) で通常の
ファイル (ordinary file) とされたファイルのみを読み込んで、タイ
プ の決定を行う。特殊ファイルを読み込むと異常な結果を引き起こす
かも知れないため、この動作により問題を防止している。 -s オプ シ
ョ ンを指定すると、 file は引き数で指定されたブロックスペシャル
ファイルやキャラクタスペシャルファイルも読み込む。ブロックス ペ
シャルファイルである raw ディスクパーティションのデータのファイ
ルシステムタイプを決定するのに役立つ。このオプションを指定す る
と file は stat(2) が返すファイルサイズを無視する。これは raw
ディスクパーティションのサイズを 0 として返すシステムも存在する
ためである。
-v, --version
プログラムのバージョンを表示して終了する。
-z, --uncompress
圧縮ファイルの中も検査する。
--help ヘルプメッセージを表示して終了する。
ファイル
/usr/share/file/magic.mgc
デフォルトのコンパイル済みのマジックナンバーのリスト。
/usr/share/file/magic
デフォルトのマジックナンバーのリスト。
/usr/share/file/magic.mime.mgc
デフォルトのコンパイル済みのマジックナンバーのリスト。 -i オプシ
ョンが指定された場合に、mime タイプを出力するのに使用される。
/usr/share/file/magic.mime
デフォルトのマジックナンバーのリスト。 -i オプションが指定された
場合に、mime タイプを出力するのに使用される。
/etc/magic
マジックナンバーについてのローカルな追加情報。
環境変数
環境変数 MAGIC はデフォルトのマジックナンバーファイルの名前を設定する。
file はこの変数の値に ".mime" と ".mgc" を適宜追加する (どちらか一方 の
場合もある)。この変数が設定されると、 file は $HOME/.magic をオープンし
ない。
関連項目
magic(4) - マジックファイルのフォーマットについての記述。
strings(1), od(1), hexdump(1) - 非テキストファイルを検査するためのツ ー
ル。
標準への準拠
こ のプログラムは System V Interface Definition の FILE(CMD) より優れて
いると考えている。ファイルに含まれている曖昧な言語から決定するという 点
で は似ている。動作は同じ名前の System V のプログラムとほぼ互換性がある
。このバージョンはより多くのマジックナンバーを認識する。しかし多くの 場
合、System V のものとは異なった (ただしもっと正確な) 出力を行う。
System V バージョンとの重要な違いは、このバージョンでは空白を区切り文字
として扱うために、パターン文字列における空白文字をしなければならない と
いう点にある。例えば、
>10 string language impress (imPRESS data)
という既存のマジックファイルは、
>10 string language\ impress (imPRESS data)
の ように変更しなければならない。更にこのバージョンでは、バックスラッシ
ュを含むパターン文字列はエスケープしなければならない。例えば、
0 string \begindata Andrew Toolkit document
という既存のマジックファイルは、
0 string \\begindata Andrew Toolkit document
のように変更しなければならない。
Sun Microsystems の SunOS releases 3.2 以降には、 System V のものから派
生した file(1) コマンドが含まれているが、いくつか拡張されている。私の作
ったバージョンは、Sun のものと些細な違いしかない。 Sun のバージョ ン は
‘&’ オペレータの拡張が含まれ、例えば以下のように使われる。
>16 long&0x7fffffff >0 not stripped
マジックディレクトリ
マ ジックファイルのエントリは、いろいろな情報源、主に USENET から集めら
れ、多くの著者から寄贈してもらった。 Christos Zoulas (アドレスは 以 下)
は マジックファイルエントリを集めたり修正したりしてくれた。マジックファ
イルのエントリを整理統合したものは、定期的に配布される予定である。
マジックファイルのエントリは順番が重要である。使用しているシステムに よ
っ ては、順番の組みが不正であるかもしれない。古い file コマンドがマジッ
クファイルを使っている場合、比較のために古いマジックファイルを残して お
くこと (/usr/share/file/magic.orig に名前を変更しておく)。
例
$ file file.c file /dev/{wd0a,hda}
file.c: C program text
file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), stripped
/dev/wd0a: block special (0/0)
/dev/hda: block special (3/0)
$ file -s /dev/wd0{b,d}
/dev/wd0b: data
/dev/wd0d: x86 boot sector
$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
/dev/hda: x86 boot sector
/dev/hda1: Linux/i386 ext2 filesystem
/dev/hda2: x86 boot sector
/dev/hda3: x86 boot sector, extended partition table
/dev/hda4: Linux/i386 ext2 filesystem
/dev/hda5: Linux/i386 swap file
/dev/hda6: Linux/i386 swap file
/dev/hda7: Linux/i386 swap file
/dev/hda8: Linux/i386 swap file
/dev/hda9: empty
/dev/hda10: empty
$ file -i file.c file /dev/{wd0a,hda}
file.c: text/x-c
file: application/x-executable, dynamically linked (uses shared libs),
not stripped
/dev/hda: application/x-not-regular-file
/dev/wd0a: application/x-not-regular-file
履歴
少 なくとも Research Version 4 以降の全ての UNIX に、 file コマンドは含
まれている (man ページの日付は 1973 年 11 月である)。 System V バージョ
ン では重大な変更が行われ、マジックナンバータイプのリストを外部に保持す
るようになった。この変更はプログラムを幾らかは遅くしたが、とても柔軟 に
した。
System V バージョンをベースにしたこのプログラムは、誰のソースコードも見
ずに Ian Darwin によって書かれた。
John Gilmore はコードを広範囲にわたって改訂し、最初のバージョンより改良
した。 Geoff Collyer はいくつかの欠点を見つけ、マジックファイルエントリ
を提供した。 ‘&’ オペレータについては 1989 年に Rob McMahon, cudcv@war-
wick.ac.uk が貢献した。
Guy Harris, guy@netapp.com は 1993 年から現在に至るまで多くの変更を行っ
ている。
Christos Zoulas (christos@astron.com) は 1990 年に最初の開発を行い、 現
在までメンテナンスを行っている。
2000 年の Chris Lowth, chris@lowth.com による変更: 別のマジックファイル
と内部ロジックを使い、 ‘‘-i’’ で mime タイプ文字列を出力するようにし た
。
2000 年 7 月の Eric Fischer (enf@pobox.com) による変更: 文字コードを識
別し、非 ASCII ファイルの言語を識別するようにした。
"Magdir" ディレクトリ (/etc/magic ファイルのソース) の貢献者のリスト は
、 長すぎるのでここには含められない。貢献してくれた人は自分が貢献したこ
とを知っているでしょう。感謝します。
法的な注意
Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. このソフト ウ
ェアは standard Berkeley Software Distribution copyright により保護され
ている。ソース配布にある LEGAL.NOTICE ファイルを参照すること。
ファイル tar.h と is_tar.c は John Gilmore によって書かれたもので、彼の
パ ブリックドメイン tar プログラムに由来する。この 2 つのファイルには上
記のライセンスが適用されない。
バグ
magdir にある全てのファイルから Magic ファイルを自動的に構築するもっ と
良 い方法があるべきだ。それはどんなものだろうか ? 起動を速くするために
は、マジックファイルをバイナリにコンパイルしておくべきだろう ( つ ま り
ndbm(3) や、異なる OS によるネットワーク環境で使うために固定長の ASCII
文字列にするのも良いだろう)。これにより、System V バージョンの柔軟性 を
備えたまま、同じ名前の Version 7 のプログラムより速くなるだろう。
file には正確さよりも速度を重視したアルゴリズムが使われているため、テキ
ストファイルの内容を読み誤ることがある。
(主にプログラミング言語を対象とした) テキストファイルのサポートは、単純
化されていて不十分であり、更新するには再コンパイルが必要である。
後続の行を追っていくためには、‘‘else’’ 節を付けておくべきである。
マ ジ ッ クファイルとキーワードで正規表現をサポートすべきである。 ASCII
TAB をフィールドの区切り文字として使用するのは、見苦しく編集しづらい が
、定着している。例えば troff(1) コマンドに対する man ページのマクロのよ
うに、キーワードで大文字を許可するようにするのが望ましいだろう。正規 表
現がサポートされれば、これが簡単にできるだろう。
このプログラムは FORTRAN を判別できない。開始行でインデントされているキ
ーワードを見て、 FORTRAN であると判断すべきである。正規表現がサポートさ
れれば、これが簡単にできるだろう。
ascmagic にあるキーワードは、多分 Magic ファイルに入れるべきだろう。こ
れはオフセット値に ‘*’ のようなキーワードを使うことで可能だろう。
その他の最適化としてはマジックファイルのソートがある。これにより一度 読
み 込んでしまえば、最初のバイト・最初のワード・最初の long 型、... とい
うように全てのテストで突き止めていくことができる。マジックファイルエ ン
ト リの衝突について苦情を言ってください。マジックファイルのエントリのソ
ートは、マジックファイルにおける位置ではなくファイルオフセットで行う 、
というルールにするべきだろうか ?
推 定した結果が「どのくらい良いか」を評価する手段を、プログラムが提供す
べきである。最終的には (例えば ‘‘Newsgroups:’’ に 対 す る ‘‘Return-
Path:’’ のように) 他の推定結果より良くない推定結果 (例えば、ファイルの
最初の 5 文字が ‘‘From ’’ など) は削除する。しかし他の推定結果が出な け
れば、最初の推定結果を使えるようにしておくべきである。
こ のプログラムは、いくつかのベンダの file コマンドより遅い。複数文字コ
ードを新しくサポートしたことで、いっそう遅くなってしまった。
この man ページ、特にこのセクションが長すぎる。
入手方法
オリジナルの作者の最新バージョンは、anonymous FTP で ftp.astron.com の
ディレクトリ /pub/file/file-X.YZ.tar.gz から入手できる。
Copyright but distributable FILE(1)
FILE(1) BSD General Commands Manual FILE(1)
NAME
file - determine file type
SYNOPSIS
file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
[-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
file -C [-m magicfiles]
file [--help]
DESCRIPTION
This manual page documents version 5.04 of the file command.
file tests each argument in an attempt to classify it. There are three
sets of tests, performed in this order: filesystem tests, magic tests,
and language tests. The first test that succeeds causes the file type to
be printed.
The type printed will usually contain one of the words text (the file
contains only printing characters and a few common control characters and
is probably safe to read on an ASCII terminal), executable (the file con-
tains the result of compiling a program in a form understandable to some
UNIX kernel or another), or data meaning anything else (data is usually
‘binary’ or non-printable). Exceptions are well-known file formats (core
files, tar archives) that are known to contain binary data. When modify-
ing magic files or the program itself, make sure to preserve these
keywords. Users depend on knowing that all the readable files in a
directory have the word ‘text’ printed. Don’t do as Berkeley did and
change ‘shell commands text’ to ‘shell script’.
The filesystem tests are based on examining the return from a stat(2)
system call. The program checks to see if the file is empty, or if it’s
some sort of special file. Any known file types appropriate to the sys-
tem you are running on (sockets, symbolic links, or named pipes (FIFOs)
on those systems that implement them) are intuited if they are defined in
the system header file
The magic tests are used to check for files with data in particular fixed
formats. The canonical example of this is a binary executable (compiled
program) a.out file, whose format is defined in #include
and possibly #include
in the standard include directory. These files have a ‘magic number’
stored in a particular place near the beginning of the file that tells
the UNIX operating system that the file is a binary executable, and which
of several types thereof. The concept of a ‘magic’ has been applied by
extension to data files. Any file with some invariant identifier at a
small fixed offset into the file can usually be described in this way.
The information identifying these files is read from the compiled magic
file /usr/share/misc/magic.mgc, or the files in the directory
/usr/share/misc/magic if the compiled file does not exist. In addition,
if $HOME/.magic.mgc or $HOME/.magic exists, it will be used in preference
to the system magic files. If /etc/magic exists, it will be used
together with other magic files.
If a file does not match any of the entries in the magic file, it is
examined to see if it seems to be a text file. ASCII, ISO-8859-x, non-
ISO 8-bit extended-ASCII character sets (such as those used on Macintosh
and IBM PC systems), UTF-8-encoded Unicode, UTF-16-encoded Unicode, and
EBCDIC character sets can be distinguished by the different ranges and
sequences of bytes that constitute printable text in each set. If a file
passes any of these tests, its character set is reported. ASCII,
ISO-8859-x, UTF-8, and extended-ASCII files are identified as ‘text’
because they will be mostly readable on nearly any terminal; UTF-16 and
EBCDIC are only ‘character data’ because, while they contain text, it is
text that will require translation before it can be read. In addition,
file will attempt to determine other characteristics of text-type files.
If the lines of a file are terminated by CR, CRLF, or NEL, instead of the
Unix-standard LF, this will be reported. Files that contain embedded
escape sequences or overstriking will also be identified.
Once file has determined the character set used in a text-type file, it
will attempt to determine in what language the file is written. The lan-
guage tests look for particular strings (cf. #include
) that can appear anywhere in the first few blocks of a file. For exam-
ple, the keyword .br indicates that the file is most likely a troff(1)
input file, just as the keyword struct indicates a C program. These
tests are less reliable than the previous two groups, so they are per-
formed last. The language test routines also test for some miscellany
(such as tar(1) archives).
Any file that cannot be identified as having been written in any of the
character sets listed above is simply said to be ‘data’.
OPTIONS
-b, --brief
Do not prepend filenames to output lines (brief mode).
-C, --compile
Write a magic.mgc output file that contains a pre-parsed version
of the magic file or directory.
-c, --checking-printout
Cause a checking printout of the parsed form of the magic file.
This is usually used in conjunction with the -m flag to debug a
new magic file before installing it.
-e, --exclude testname
Exclude the test named in testname from the list of tests made to
determine the file type. Valid test names are:
apptype EMX application type (only on EMX).
text Various types of text files (this test will try to
guess the text encoding, irrespective of the setting of
the ‘encoding’ option).
encoding Different text encodings for soft magic tests.
tokens Looks for known tokens inside text files.
cdf Prints details of Compound Document Files.
compress Checks for, and looks inside, compressed files.
elf Prints ELF file details.
soft Consults magic files.
tar Examines tar files.
-F, --separator separator
Use the specified string as the separator between the filename
and the file result returned. Defaults to ‘:’.
-f, --files-from namefile
Read the names of the files to be examined from namefile (one per
line) before the argument list. Either namefile or at least one
filename argument must be present; to test the standard input,
use ‘-’ as a filename argument.
-h, --no-dereference
option causes symlinks not to be followed (on systems that sup-
port symbolic links). This is the default if the environment
variable POSIXLY_CORRECT is not defined.
-i, --mime
Causes the file command to output mime type strings rather than
the more traditional human readable ones. Thus it may say
‘text/plain; charset=us-ascii’ rather than ‘ASCII text’. In
order for this option to work, file changes the way it handles
files recognized by the command itself (such as many of the text
file types, directories etc), and makes use of an alternative
‘magic’ file. (See the FILES section, below).
--mime-type, --mime-encoding
Like -i, but print only the specified element(s).
-k, --keep-going
Don’t stop at the first match, keep going. Subsequent matches
will be have the string ‘\012- ’ prepended. (If you want a new-
line, see the ‘-r’ option.)
-L, --dereference
option causes symlinks to be followed, as the like-named option
in ls(1) (on systems that support symbolic links). This is the
default if the environment variable POSIXLY_CORRECT is defined.
-m, --magic-file magicfiles
Specify an alternate list of files and directories containing
magic. This can be a single item, or a colon-separated list. If
a compiled magic file is found alongside a file or directory, it
will be used instead.
-N, --no-pad
Don’t pad filenames so that they align in the output.
-n, --no-buffer
Force stdout to be flushed after checking each file. This is
only useful if checking a list of files. It is intended to be
used by programs that want filetype output from a pipe.
-p, --preserve-date
On systems that support utime(2) or utimes(2), attempt to pre-
serve the access time of files analyzed, to pretend that file
never read them.
-r, --raw
Don’t translate unprintable characters to \ooo. Normally file
translates unprintable characters to their octal representation.
-s, --special-files
Normally, file only attempts to read and determine the type of
argument files which stat(2) reports are ordinary files. This
prevents problems, because reading special files may have pecu-
liar consequences. Specifying the -s option causes file to also
read argument files which are block or character special files.
This is useful for determining the filesystem types of the data
in raw disk partitions, which are block special files. This
option also causes file to disregard the file size as reported by
stat(2) since on some systems it reports a zero size for raw disk
partitions.
-v, --version
Print the version of the program and exit.
-z, --uncompress
Try to look inside compressed files.
-0, --print0
Output a null character ‘\0’ after the end of the filename. Nice
to cut(1) the output. This does not affect the separator which is
still printed.
--help Print a help message and exit.
FILES
/usr/share/misc/magic.mgc Default compiled list of magic.
/usr/share/misc/magic Directory containing default magic files.
ENVIRONMENT
The environment variable MAGIC can be used to set the default magic file
name. If that variable is set, then file will not attempt to open
$HOME/.magic. file adds ‘.mgc’ to the value of this variable as appro-
priate. The environment variable POSIXLY_CORRECT controls (on systems
that support symbolic links), whether file will attempt to follow sym-
links or not. If set, then file follows symlink, otherwise it does not.
This is also controlled by the -L and -h options.
SEE ALSO
magic(5), strings(1), od(1), hexdump(1,) file(1posix)
STANDARDS CONFORMANCE
This program is believed to exceed the System V Interface Definition of
FILE(CMD), as near as one can determine from the vague language contained
therein. Its behavior is mostly compatible with the System V program of
the same name. This version knows more magic, however, so it will pro-
duce different (albeit more accurate) output in many cases.
The one significant difference between this version and System V is that
this version treats any white space as a delimiter, so that spaces in
pattern strings must be escaped. For example,
>10 string language impress (imPRESS data)
in an existing magic file would have to be changed to
>10 string language\ impress (imPRESS data)
In addition, in this version, if a pattern string contains a backslash,
it must be escaped. For example
0 string \begindata Andrew Toolkit document
in an existing magic file would have to be changed to
0 string \\begindata Andrew Toolkit document
SunOS releases 3.2 and later from Sun Microsystems include a file command
derived from the System V one, but with some extensions. My version dif-
fers from Sun’s only in minor ways. It includes the extension of the ‘&’
operator, used as, for example,
>16 long&0x7fffffff >0 not stripped
MAGIC DIRECTORY
The magic file entries have been collected from various sources, mainly
USENET, and contributed by various authors. Christos Zoulas (address
below) will collect additional or corrected magic file entries. A con-
solidation of magic file entries will be distributed periodically.
The order of entries in the magic file is significant. Depending on what
system you are using, the order that they are put together may be incor-
rect. If your old file command uses a magic file, keep the old magic
file around for comparison purposes (rename it to
/usr/share/misc/magic.orig ).
EXAMPLES
$ file file.c file /dev/{wd0a,hda}
file.c: C program text
file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), stripped
/dev/wd0a: block special (0/0)
/dev/hda: block special (3/0)
$ file -s /dev/wd0{b,d}
/dev/wd0b: data
/dev/wd0d: x86 boot sector
$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
/dev/hda: x86 boot sector
/dev/hda1: Linux/i386 ext2 filesystem
/dev/hda2: x86 boot sector
/dev/hda3: x86 boot sector, extended partition table
/dev/hda4: Linux/i386 ext2 filesystem
/dev/hda5: Linux/i386 swap file
/dev/hda6: Linux/i386 swap file
/dev/hda7: Linux/i386 swap file
/dev/hda8: Linux/i386 swap file
/dev/hda9: empty
/dev/hda10: empty
$ file -i file.c file /dev/{wd0a,hda}
file.c: text/x-c
file: application/x-executable
/dev/hda: application/x-not-regular-file
/dev/wd0a: application/x-not-regular-file
HISTORY
There has been a file command in every UNIX since at least Research
Version 4 (man page dated November, 1973). The System V version intro-
duced one significant major change: the external list of magic types.
This slowed the program down slightly but made it a lot more flexible.
This program, based on the System V version, was written by Ian Darwin
without looking at anybody else’s source code.
John Gilmore revised the code extensively, making it better than the
first version. Geoff Collyer found several inadequacies and provided
some magic file entries. Contributions by the ‘&’ operator by Rob McMa-
hon, cudcv@warwick.ac.uk, 1989.
Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
Primary development and maintenance from 1990 to the present by Christos
Zoulas (christos@astron.com).
Altered by Chris Lowth, chris@lowth.com, 2000: Handle the -i option to
output mime type strings, using an alternative magic file and internal
logic.
Altered by Eric Fischer (enf@pobox.com), July, 2000, to identify charac-
ter codes and attempt to identify the languages of non-ASCII files.
Altered by Reuben Thomas (rrt@sc3d.org), 2007 to 2008, to improve MIME
support and merge MIME and non-MIME magic, support directories as well as
files of magic, apply many bug fixes and improve the build system.
The list of contributors to the ‘magic’ directory (magic files) is too
long to include here. You know who you are; thank you. Many contribu-
tors are listed in the source files.
LEGAL NOTICE
Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. Covered by the
standard Berkeley Software Distribution copyright; see the file
LEGAL.NOTICE in the source distribution.
The files tar.h and is_tar.c were written by John Gilmore from his pub-
lic-domain tar(1) program, and are not covered by the above license.
BUGS
There must be a better way to automate the construction of the Magic file
from all the glop in Magdir. What is it?
file uses several algorithms that favor speed over accuracy, thus it can
be misled about the contents of text files.
The support for text files (primarily for programming languages) is sim-
plistic, inefficient and requires recompilation to update.
The list of keywords in ascmagic probably belongs in the Magic file.
This could be done by using some keyword like ‘*’ for the offset value.
Complain about conflicts in the magic file entries. Make a rule that the
magic entries sort based on file offset rather than position within the
magic file?
The program should provide a way to give an estimate of ‘how good’ a
guess is. We end up removing guesses (e.g. ‘Fromas first 5 chars of
file) because’ they are not as good as other guesses (e.g. ‘Newsgroups:’
versus ‘Return-Path:’ ). Still, if the others don’t pan out, it should
be possible to use the first guess.
This manual page, and particularly this section, is too long.
RETURN CODE
file returns 0 on success, and non-zero on error.
If the file named by the file operand does not exist, cannot be read, or
the type of the file named by the file operand cannot be determined, this
is not be considered an error that affects the exit status.
AVAILABILITY
You can obtain the original author’s latest version by anonymous FTP on
ftp.astron.com in the directory /pub/file/file-X.YZ.tar.gz
BSD October 9, 2008 BSD