命令介紹
命令:file 查看文件類型
用法:file [OPTION…] [FILE…] file 選項 文件
命令選項
[root@fp-21 ~]# file --help
-z, --uncompress # 嘗試查看壓縮文件
-b, --brief # 不在輸出行面前加文件名
-c, --checking-printout # 詳細顯示指令執行過程,便於排錯或分析程序執行的情形
-e, --exclude TEST # 從要對文件執行的測試列表中排除測試
-f, --files-from FILE # 指定文件,判斷內容中的文件名的文件類型
-F, --separator STRING # 以指定的字符串作爲分隔符
-i, --mime # 以 MIME 類型字符串輸出
--apple # 以 Apple 類型輸出
--mime-type # 以 MIME 類型輸出
--mime-encoding # 以 MIME 編碼輸出
-L, --dereference # 直接顯示符號連接所指向的文件的類別
-0, --print0 # 用ASCII NUL終止文件名
-p, --preserve-date # 保留文件的訪問時間
-r, --raw # 不要將無法打印的字符轉換爲\ooo
-s, --special-files # 將特殊(塊/字符設備)文件視爲普通文件
-C, --compile # 編譯由-m指定的文件
-d, --debug # 打印調試信息
--help # 幫助文檔
-v, --version # 版本信息
命令實例
# 查看文件類型
[root@fp-21 ~]# file test_file
test_file: ASCII text
[root@fp-21 ~]# file test_dir
test_dir: directory
[root@fp-21 ~]# file file
file: symbolic link to 'test_file'
# 嘗試查看壓縮文件
[root@fp-21 ~]# file -z mysql-5.6.45.tar.gz
mysql-5.6.45.tar.gz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified: Mon Jun 10 18:31:21 2019)
# 不在輸出行面前加文件名
[root@fp-21 ~]# file 777
777: directory
[root@fp-21 ~]# file -b 777
directory
# 指定文件,判斷內容中的文件名的文件類型
[root@fp-21 ~]# mkdir test_dir
[root@fp-21 ~]# echo "test_dir" >> test_file
[root@fp-21 ~]# echo "test_file" >> test_file
[root@fp-21 ~]# file -f test_file
test_dir: directory
test_file: ASCII text
# 以指定的字符串作爲分隔符
[root@fp-21 ~]# file -F " -->" test_file
test_file --> ASCII text
# 以 MIME 類型字符串輸出
[root@fp-21 ~]# file -i test_file
test_file: text/plain; charset=us-ascii