file
ファイルとディレクトリ
書き方
file [path]名前ではなく中身を見て種類を判定します。拡張子を無視するので、.jpg のはずが実は PDF だったという事故がここで見つかります。
よく使うオプション
| オプション | 意味 |
|---|---|
| -b | Print only the description, without the file name |
| --mime-type | Print the MIME type; the short form is -i on GNU, -I on macOS |
| -L | Follow symlinks |
| -z | Look inside compressed files |
| -s | Read block and character devices too |
| -i | On BSD and macOS this means do not classify contents, not MIME |
例
file screenshotSays PNG image data even with no extension.
file -b --mime-type report.pdfPrints application/pdf and nothing else.
file *Types every entry in this directory.
移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. file は何をしますか。
名前ではなく中身を見て種類を判定します。拡張子を無視するので、.jpg のはずが実は PDF だったという事故がここで見つかります。
Q. どう打ちますか。
file [path] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man file にあります。このコマンドはファイルとディレクトリの仲間です。
関連するコマンド
man ページ: man file