简介
file命令用来查看文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的。
命令格式
file [-bcLvz] [-f <名称文件>] [-m <魔法数字文件>…] [文件或目录…]
常用参数
| -b | 列出辨识结果时,不显示文件名称 (简要模式) |
|---|---|
| -i | 显示MIME类别 |
| -L | 直接显示符号连接所指向的文件类别 |
| -F separator | 使用指定的字符串作为文件名和文件结果之间的分隔符返回。默认为“:”。 |
MIME类别
| text/plain | 普通文本 |
|---|---|
| text/html | HTML文本 |
| application/pdf | PDF文档 |
| application/msword | Word文档 |
| image/png | PNG图片 |
| image/jpeg | JPEG图片 |
| application/x-tar | TAR文件 |
| application/x-gzip | GZIP文件 |
示例
[root@localhost ~]# echo '我爱中国' > install.log[root@localhost ~]# file install.loginstall.log: UTF-8 Unicode text[root@localhost ~]# file -b install.logUTF-8 Unicode text[root@localhost ~]# file -i install.loginstall.log: text/plain; charset=utf-8[root@localhost ~]# file -i -b install.logtext/plain; charset=utf-8[root@localhost ~]# mkdir a[root@localhost ~]# ln -s a b[root@localhost ~]# ls -l blrwxrwxrwx. 1 root root 1 Apr 20 16:39 b -> a[root@localhost ~]# file bb: symbolic link to `a'[root@localhost ~]# file -L bb: directory[root@localhost ~]# file install.loginstall.log: UTF-8 Unicode text[root@localhost ~]# file -F ' => ' install.loginstall.log => UTF-8 Unicode text[root@localhost ~]# which --skip-alias ls/usr/bin/ls[root@localhost ~]# file /usr/bin/ls/usr/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x7dc964034aa8ec7327b3992e3239a0f50789a3dd, stripped
