http://www.csdn.net/ http://www.arm.com/zh/ https://www.kernel.org/ http://www.linuxpk.com/ http://www.51develop.net/ http://linux.chinaitlab.com/ http://www.embeddedlinux.org.cn http://bbs.pediy.com/
分类: linux
2018-09-07 16:58:00
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】脚本学习