摘自:http://codingstandards.iteye.com/blog/804463

我使用过的Linux命令之file - 检测并显示文件类型

用途说明

file命令是用来检测并显示文件类型(determine file type)。

常用参数

-b  不显示文件名称,只显示文件类型。在shell脚本中时有用。

-i     显示MIME类别。

-L  直接显示符号连接所指向的文件的类别。

-f namefile    指定名称文件(namefile),该文件每一行为一个文件名,file命令将按每一行的文件名辨别该文件的类型

使用示例

示例一 显示文件类型

[root@web ~]# file install.log

install.log: UTF-8 Unicode text

[root@web ~]# file -b install.log
    
<== 不显示文件名称

UTF-8 Unicode text

[root@web ~]# file -i install.log      <== 显示MIME类别。

install.log: text/plain; charset=utf-8

[root@web ~]# file -b -i install.log

text/plain; charset=utf-8

[root@web ~]#

示例二 显示符号链接的文件类型

[root@rhel55 ~]# ls -l /var/mail

lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail

[root@rhel55 ~]# file /var/mail

/var/mail: symbolic link to `spool/mail'
[root@rhel55 ~]# file -L /var/mail

/var/mail: directory
[root@rhel55 ~]# file /var/spool/mail

/var/spool/mail: directory
[root@rhel55 ~]# file -L /var/spool/mail

/var/spool/mail: directory
[root@rhel55 ~]#

示例三

[root@web186 root]# file *

1.sh:                                      ASCII text
1.txt:                                     empty
20080308xzmf.txt:                          ASCII text, with CRLF line terminators
448FD15874B0DC51.wav:                      RIFF (little-endian) data, WAVE audio, ITU G.711 a-law, mono 8000 Hz
449110BA327B23C6.vox:                      8086 relocatable (Microsoft)

600d.wav:                                  RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
anaconda-ks.cfg:                           ASCII English text
banner.swf:                                data
commons-beanutils.jar:                     Zip archive data, at least v1.0 to extract
cvs_accept.sh:                             Bourne shell script text executable
data:                                      directory
employer0605.txt:                          Non-ISO extended-ASCII text
GetFirstFile.class:                        compiled Java class data, version 49.0
GetFirstFile.java:                         ASCII Java program text
HELPFILE:                                  C++ program text
httptunnel.zip:                            Zip archive data, at least v2.0 to extract
iptables_man.txt:                          ASCII English text, with overstriking
lnx61su_171.tar.gz:                        gzip compressed data, from Unix
megamgr.bin.filepart:                      ELF 32-bit LSB executable,
Intel 80386, version 1 (SYSV), for GNU/Linux 2.0.0, statically linked,
stripped
MegaPR_Linux_A02.tar.gz:                   gzip compressed data, was "MegaPR_Linux_A02.tar", from Win/32
mess0429.txt:                              ISO-8859 text, with very long lines
smartmontools-5.36.tar.gz:                 gzip compressed data, from Unix, max compression
sms.qunfa:                                 ELF 32-bit LSB executable,
Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked
(uses shared libs), not stripped
sms.vip.cfg:                               ISO-8859 text, with very long lines
top.txt:                                   ASCII text, with CRLF, LF line terminators
voice20061128.rar:                         RAR archive data
vox2amr.sh:                                Bourne-Again shell script text executable
[root@web186 root]#

注:使用file命令显示出来的文件类型有些情况下不一定太准确,如上面黑体显示的.vox文件格式,应该是Dialogic VOX File格式的。

问题思考

1. 怎样自定义某种文件类型?

相关资料

【1】脚本学习 linux file命令: 辨别文件类型

返回 我使用过的Linux命令系列总目录

我使用过的Linux命令之file - 检测并显示文件类型的更多相关文章

  1. linux命令学习——file

    1.简介 file命令是用来检测并显示文件类型(determine file type).通过file指令,我们得以辨识该文件的类型,例如可以知道动态连接库是32位还是64位. 2.命令格式 file ...

  2. 每天一个linux命令:file(11)

    file file命令用来探测给定文件的类型.file命令对文件的检查分为文件系统.魔法幻数检查和语言检查3个过程. 格式 file [选项] [参数] 参数选项 参数 备注 -b 列出辨识结果时,不 ...

  3. linux 命令之file

    Linux file命令用于辨识文件类型. 通过file指令,我们得以辨识该文件的类型. 语法 file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...] ...

  4. Linux命令之file

    file [选项] [文件名] 确认文件类型 (1).常用选项 magic file指的是哪些具有特殊文件格式的文件 -b,--brief 不列出文件名称 -c,--checking-printout ...

  5. Linux命令之 file命令

    该命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 执行权限 :All User 指令所在路径:/us ...

  6. linux命令(49):显示文件的指定行,打印中间几行

    linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...

  7. 【改造Linux命令之rm - 删除文件或目录-】

    用途说明 rm命令是常用的命令,用来删除文件或目录(remove files or directories).它也是一个危险的命令,使用的时候要特别当心,尤其对于新手,否则整个系统就会毁在这个命令(比 ...

  8. 十年linux命令总结

    十年linux命令总结 本文链接: http://codingstandards.iteye.com/blog/786653 关于命令类型划分 本表中列出了我穷尽了我所有的记忆整理出来的Linux命令 ...

  9. 初识50个Linux命令

    1. [命令]:cat [功能说明]: concatenate files and print on the standard output #连接文件并打印到标准输出,有标准输出的都可以用重定向定向 ...

随机推荐

  1. Quartz.NET作业调度框架详解

    Quartz.NET作业调度框架详解 http://www.cnblogs.com/lmule/archive/2010/08/28/1811042.html

  2. Binary Search Tree Iterator 解答

    Question Implement an iterator over a binary search tree (BST). Your iterator will be initialized wi ...

  3. wget命令1(转载)

    Linux系统中的wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持HTTP,HTTPS和FTP协 ...

  4. js点击事件防止用户重复点击执行

    点击事件里给button标签加一个自定义属性,存上次点击时间 追问: 求详细代码,JS 真心的没怎么做过 追答:   <input type="button" id=&quo ...

  5. Js数组的操作push,pop,shift,unshift等方法详细介绍

    js中针对数组操作的方法还是比较多的,今天突然想到来总结一下,也算是温故而知新吧.不过不会针对每个方法进行讲解,我只是选择其中的一些来讲. 首 先来讲一下push和pop方法,这两个方法只会对数组从尾 ...

  6. Kolor Neutralhazer v1.0.2 (照片雾气模糊去除过滤器)+破解RI

    由于空气污染.阴霾几天越来越,根据照片始终是一个灰色,怎么做?有了这个插件.能够解除您的烦恼. Neutralhazer这是消除你的风景照片和雾气模糊的全景图的有效途径photoshop小工具. wa ...

  7. apache如何在虚拟主机中实现用户验证

    1,在相应的虚拟主机配置文件段,加入<Directory  /data/www.admin.php>                AllowOverride AuthConfig     ...

  8. C# winform平台下使用spread控件导出excel表格

    //首先要引入两个控件:1.根据自己的office 版本在项目->添加引用->microsoft office object 12.0 library (2010版) //2.在.net中 ...

  9. easyui placeholder 解决方案

    最近,再用easyui的时候,发现easyui的input标签不支持h5的placeholder,为了实现这个效果,提供以下解决方案: 1.给input标签设置placeholder. <td& ...

  10. android开发工具类总结(一)

    一.日志工具类 Log.java public class L { private L() { /* 不可被实例化 */ throw new UnsupportedOperationException ...