- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業務經營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯網協會理事單位
- 安全聯盟認證網站身份V標記
- 域名注冊服務機構許可:滇D3-20230001
- 代理域名注冊服務機構:新網數碼
命令簡介:
該命令用來識別文件類型,也可用來辨別一些文件的編碼格式。它是通過查看文件的頭部信息來獲取文件類型,而不是像Windows通過擴展名來確定文件類型的。
執行權限 :All User
指令所在路徑:/usr/bin/file
命令語法:
file [ -bchikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles ] file ...
命令參數:
下表列出?部分常用的參數。
參數 | 長參數 | 描敘 |
-b | 列出文件辨識結果時,不顯示文件名稱。 | |
-c | 詳細顯示指令執行過程,便于排錯或分析程序執行的情形 | |
-f | 列出文件中文件名的文件類型 | |
-F | 使用指定分隔符號替換輸出文件名后的默認的“:”分隔符。 | |
-i | 輸出mime類型的字符串 | |
-L | 查看對應軟鏈接對應文件的文件類型 | |
-z | 嘗試去解讀壓縮文件的內容 | |
--help | 顯示命令在線幫助 | |
--version | 顯示命令版本信息 |
使用示例:
1:查看file命令的幫助信息
[root@DB-Server ~]# file --help
Usage: file [OPTION]... [FILE]...
Determine file type of FILEs.
-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:查看文件類型
例如,如下所示,Temp.txt 文件類型為text,編碼為UTF-8 Unicode
[root@DB-Server ~]# file Temp.txt
Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators
3:不輸出文件名稱,只顯示文件格式以及編碼
通過下面兩個命令對時,就可以清晰的了解參數-b的作用。
[root@DB-Server ~]# file Temp.txt
Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators
[root@DB-Server ~]# file -b Temp.txt
UTF-8 Unicode text, with very long lines, with CRLF line terminators
4: 輸出mime類型的字符串
[root@DB-Server ~]# file -i Temp.txt
Temp.txt: text/plain; charset=utf-8
5: 查看文件中的文件名的文件類型
這個參數非常適合shell腳本去查找、判別某種文件類型的數據。
[root@DB-Server ~]# cat >test
/root/install.log
it is only one test file
[2]+ Stopped cat > test
[root@DB-Server ~]# file -f test
/root/install.log: ASCII text
it is only one test file: ERROR: cannot open `it is only one test file' (No such file or directory)
[root@DB-Server ~]#
[root@DB-Server ~]#
5: 使用指定分隔符號替換輸出文件名后的默認的“:”分隔符。
感覺這個參數很雞肋!我搞明白這個參數的作用時,很是納悶。
6:嘗試去解讀壓縮文件的內容
[root@DB-Server ~]# file -z Temp.txt.gz
Temp.txt.gz: UTF-8 Unicode text, with very long lines, with CRLF line terminators (gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014)
[root@DB-Server ~]#
7: 查看軟鏈接對應文件的文件類型
如下所示,創建一個軟鏈接sfile,然后分別用file 和帶參數的file -L查看
[root@DB-Server ~]# ln -s Temp.txt.gz sfile
[root@DB-Server ~]# file sfile
sfile: symbolic link to `Temp.txt.gz'
[root@DB-Server ~]# file -L sfile
sfile: gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014
[root@DB-Server ~]#
提交成功!非常感謝您的反饋,我們會繼續努力做到更好!
這條文檔是否有幫助解決問題?
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP