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