歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux命令 >> Linux file命令參數及使用方法詳解

Linux file命令參數及使用方法詳解

日期:2017/2/27 16:37:31   编辑:Linux命令
功能說明:file命令是用來檢測並顯示文件類型(determine file type)。
語  法:file [-beLvz][-f <名稱文件>][-m <魔法數字文件>...][文件或目錄...]
參  數:
 -b  列出辨識結果時,不顯示文件名稱。
 -c  詳細顯示指令執行過程,便於排錯或分析程序執行的情形。
 -f<名稱文件>  指定名稱文件,其內容有一個或多個文件名稱呢感,讓file依序辨識這些文件,格式為每列一個文件名稱。
 -L  直接顯示符號連接所指向的文件的類別。
 -m<魔法數字文件>  指定魔法數字文件。
 -v  顯示版本信息。
 -z  嘗試去解讀壓縮文件的內容。

使用示例
示例一:顯示文件類型
[root@server1 linuxeye]# file linuxeye.com
linuxeye.com: ASCII text
[root@server1 linuxeye]# file -b linuxeye.com <== 不顯示文件名稱
ASCII text
[root@server1 linuxeye]# file -i linuxeye.com <== 顯示MIME類別
linuxeye.com: text/plain; charset=us-ascii
[root@server1 linuxeye]# file -b -i linuxeye.com
text/plain; charset=us-ascii

示例二:顯示符號鏈接的文件類型
[root@server1 linuxeye]# ll /boot/grub/menu.lst
lrwxrwxrwx 1 root root 11 Nov 9 2011 /boot/grub/menu.lst -> ./grub.conf
[root@server1 linuxeye]# file /boot/grub/menu.lst
/boot/grub/menu.lst: symbolic link to `./grub.conf'
[root@server1 linuxeye]# file -L /boot/grub/menu.lst
/boot/grub/menu.lst: ASCII text

示例三:
[root@server1 test]# file *
filestat.sh: Bourne-Again shell script text executable
linuxeye: directory
other: ASCII text
remove_duplicates.sh: Bourne-Again shell script text executable
test: ASCII text
test_copy1: ASCII text
test_copy2: ASCII text
449110BA327B23C6.vox: 8086 relocatable (Microsoft)
注:使用file命令顯示出來的文件類型有些情況下不一定太准確,如上面黑體顯示的.vox文件格式,應該是Dialogic VOX File格式的。
Copyright © Linux教程網 All Rights Reserved