首页 » file - 查看文件类型

file命令用于查看文件类型,几乎所有常见文件类型file都能判断:

$ file -b /bin/ls
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

file不会理会文件后缀,而是通过分析文件并结合/usr/share/file/magic.mgc文件判断:

$ file /usr/share/file/*
/usr/share/file/magic:          magic text file for file(1) cmd
/usr/share/file/magic.mgc:      magic binary file for file(1) cmd (version 2) (little endian)
/usr/share/file/magic.mime:     magic text file for file(1) cmd
/usr/share/file/magic.mime.mgc: magic binary file for file(1) cmd (version 2) (little endian)

除了判断文件类型,file有时还会输出一些有趣的文件信息。

输出.tar.bz2文件分块大小

$ file -b wireshark-1.7.1.tar.bz2 
bzip2 compressed data, block size = 900k

输出.tar.gz文件最后修改时间

$ file -b zhcon-0.2.3.tar.gz 
gzip compressed data, from Unix, last modified: Mon Apr 28 22:42:42 2003, max compression

输出.jpg文件的注释

$ file -b images/200px-Rosetta_Stone.jpg
JPEG image data, JFIF standard 1.01, comment: "File source: http://commons.wik"

输出.png文件长宽像素(有.jpg文件被修改为.png的,被file发现了):

$ file -b *.png
PNG image data, 500 x 333, 8-bit/color RGB, non-interlaced
PNG image data, 120 x 120, 8-bit/color RGBA, non-interlaced
PNG image data, 200 x 33, 8-bit gray+alpha, non-interlaced
PNG image data, 640 x 480, 8-bit colormap, non-interlaced
JPEG image data, JFIF standard 1.01

分享

0