5ucms论坛

标题: Linux命令详解-file [打印本页]

作者: admin    时间: 2018-11-21 08:56
标题: Linux命令详解-file
Linux file命令用于辨识文件类型。

通过file指令,我们得以辨识该文件的类型。

语法
file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...][文件或目录...]
参数:

  1. -b  列出辨识结果时,不显示文件名称。
  2. -c  详细显示指令执行过程,便于排错或分析程序执行的情形。
  3. -f<名称文件>  指定名称文件,其内容有一个或多个文件名称时,让file依序辨识这些文件,格式为每列一个文件名称。
  4. -L  直接显示符号连接所指向的文件的类别。
  5. -m<魔法数字文件>  指定魔法数字文件。
  6. -v  显示版本信息。
  7. -z  尝试去解读压缩文件的内容。
  8. [文件或目录...] 要确定类型的文件列表,多个文件之间使用空格分开,可以使用shell通配符匹配多个文件。
复制代码

实例
显示文件类型:

  1. [root@localhost ~]# file install.log
  2. install.log: UTF-8 Unicode text

  3. [root@localhost ~]# file -b install.log      <== 不显示文件名称
  4. UTF-8 Unicode text

  5. [root@localhost ~]# file -i install.log      <== 显示MIME类别。
  6. install.log: text/plain; charset=utf-8

  7. [root@localhost ~]# file -b -i install.log
  8. text/plain; charset=utf-8
复制代码

显示符号链接的文件类型

  1. [root@localhost ~]# ls -l /var/mail
  2. lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail

  3. [root@localhost ~]# file /var/mail
  4. /var/mail: symbolic link to `spool/mail'

  5. [root@localhost ~]# file -L /var/mail
  6. /var/mail: directory

  7. [root@localhost ~]# file /var/spool/mail
  8. /var/spool/mail: directory

  9. [root@localhost ~]# file -L /var/spool/mail
  10. /var/spool/mail: directory
复制代码





欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2