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

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

本文链接:http://codingstandards.iteye.com/blog/804463   (转载请注明出处)

用途说明

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命令系列总目录

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值