2019-04-21 11:50:48 +08:00

48 lines
2.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="file">file</h1>
<p>用来探测给定文件的类型。</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>file命令</strong> 用来探测给定文件的类型。file命令对文件的检查分为文件系统、魔法幻数检查和语言检查3个过程。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">file(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-b列出辨识结果时不显示文件名称
-c详细显示指令执行过程便于排错或分析程序执行的情形
-f&lt;名称文件&gt;指定名称文件其内容有一个或多个文件名称时让file依序辨识这些文件格式为每列一个文件名称
-L直接显示符号连接所指向的文件类别
-m&lt;魔法数字文件&gt;:指定魔法数字文件;
-v显示版本信息
-z尝试去解读压缩文件的内容。</code></pre>
<h3 id="参数">参数</h3>
<p>文件要确定类型的文件列表多个文件之间使用空格分开可以使用shell通配符匹配多个文件。</p>
<h3 id="实例">实例</h3>
<p>显示文件类型</p>
<pre><code class="language-bash">[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log &lt;== 不显示文件名称
UTF-8 Unicode text
[root@localhost ~]# file -i install.log &lt;== 显示MIME类别。
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8
</code></pre>
<p>显示符号链接的文件类型</p>
<pre><code class="language-bash">[root@localhost ~]# ls -l /var/mail
lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -&gt; spool/mail
[root@localhost ~]# file /var/mail
/var/mail: symbolic link to `spool/mail&#39;
[root@localhost ~]# file -L /var/mail
/var/mail: directory
[root@localhost ~]# file /var/spool/mail
/var/spool/mail: directory
[root@localhost ~]# file -L /var/spool/mail
/var/spool/mail: directory
</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->