命令簡介:
該命令用來識別文件類型,也可用來辨別一些文件的編碼格式。它是通過查看文件的頭部信息來獲取文件類型,而不是像Windows通過擴展名來確定文件類型的。
執行權限 :All User
指令所在路徑:/usr/bin/file
命令語法:
命令參數:
下表列出了部分常用的參數。 
使用示例:
1:查看file命令的幫助信息
-m, --magic-file LIST use LIST as a colon-separated list of magic number files
-z, --uncompress try to look inside compressed files
-b, --brief do not prepend filenames to output lines
-c, --checking-printout print the parsed form of the magic file, use in conjunction with -m to debug a new magic file before installing it
-f, --files-from FILE read the filenames to be examined from FILE
-F, --separator string use string as separator instead of `:'
-i, --mime output mime type strings
-k, --keep-going don't stop at the first match
-L, --dereference causes symlinks to be followed -n, --no-buffer do not buffer output
-N, --no-pad do not pad output
-p, --preserve-date preserve access times on files
-r, --raw don't translate unprintable chars to /ooo
-s, --special-files treat special (block/char devices) files as ordinary ones
--help display this help and exit
--version output version information and exit
當然你也可以使用 man file 獲取更加詳細的幫助文檔信息。
2:不輸出文件名稱,只顯示文件格式以及編碼
通過下面兩個命令對時,就可以清晰的了解參數-b的作用。

4: 查看文件中的文件名的文件類型
這個參數非常適合shell腳本去查找、判別某種文件類型的數據。
你可以像下面這樣使用 file 命令確定文件的類型。下面的截圖顯示了用 file 命令確定不同文件類型的例子。
5:嘗試去解讀壓縮文件的內容
6: 查看軟鏈接對應文件的文件類型
如下所示,創建一個軟鏈接sfile,然后分別用file 和帶參數的file -L查看
新聞熱點
疑難解答