博客
关于我
Linux 文件管理 : file 命令详解
阅读量:245 次
发布时间:2019-03-01

本文共 1310 字,大约阅读时间需要 4 分钟。

file命令用来探测给定文件的类型。file命令对文件的检查分为文件系统、魔法幻数检查和语言检查3个过程。

语法

file(选项)(参数)

选项

-b:列出辨识结果时,不显示文件名称;-c:详细显示指令执行过程,便于排错或分析程序执行的情形;-f
<名称文件>
:指定名称文件,其内容有一个或多个文件名称时,让file依序辨识这些文件,格式为每列一个文件名称;-L:直接显示符号连接所指向的文件类别;-m
<魔法数字文件>
:指定魔法数字文件;-v:显示版本信息;-z:尝试去解读压缩文件的内容。

参数

文件:要确定类型的文件列表,多个文件之间使用空格分开,可以使用shell通配符匹配多个文件。

实例

显示文件类型

[root@localhost ~]# file install.loginstall.log: UTF-8 Unicode text[root@localhost ~]# file -b install.log      <== 不显示文件名称UTF-8 Unicode text[root@localhost ~]# file -i install.log      <== 显示MIME类别。install.log: text/plain; charset=utf-8[root@localhost ~]# file -b -i install.logtext/plain; charset=utf-8

显示符号链接的文件类型

[root@localhost ~]# ls -l /var/maillrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail[root@localhost ~]# file /var/mail/var/mail: symbolic link to `spool/mail'[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

详解:

 

实例1:查看文件类型

命令:

file Temp.txt

输出:

    

实例2:不输出文件名称,只显示文件格式以及编码

命令:

file –b Temp.txt

输出:

 

实例3:输出mime类型的字符串

命令:

file –i Temp.txt

输出:

 

实例3:查看文件中的文件名的文件类型

命令:

file -f test

输出:

 

实例4:使用指定分隔符号替换输出文件名后的默认的":"分隔符。

命令:

file –F "--" test

输出:

 

实例5:尝试去解读压缩文件的内容

命令:

file –z test.gz

输出:

 

实例6:查看软链接对应文件的文件类型

命令:

 

        file -L file

 

输出:

 

转载地址:http://veut.baihongyu.com/

你可能感兴趣的文章
NFS远程目录挂载
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
ng6.1 新特性:滚回到之前的位置
查看>>
nghttp3使用指南
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(一)—— 组件介绍
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + Tomcat + SpringBoot 部署项目
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>
nginx - thinkphp 如何实现url的rewrite
查看>>
Nginx - 反向代理、负载均衡、动静分离、底层原理(案例实战分析)
查看>>
Nginx - 反向代理与负载均衡
查看>>
nginx 1.24.0 安装nginx最新稳定版
查看>>