ファイルの種類をまとめて調べる

特定ディレクトリ配下にあるファイルの種類をまとめて調べるワンライナーです。

 # find [directory] -type f -print0 | xargs -0 file | sort


以下実行例です。

# find . -type f -print0 | xargs -0 file | sort
./README.html: HTML document text
./README:      ASCII English text
./a.gif:       GIF image data, version 89a, 20 x 22
./a.jpg:       JPEG image data, JFIF standard 1.01
./a.png:       PNG image data, 20 x 22, 4-bit colormap, non-interlaced
./echo:        ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
./hosts.gz:    gzip compressed data, was "hosts", from Unix, last modified: Thu Jul  1 15:28:53 2010
./network:     Bourne-Again shell script text executable
./sysctl.conf: ASCII English text


fileコマンドですが、「-i」オプションでmime形式で表示、
「-z」オプションで圧縮されたファイルの中身も確認します。

# file hosts.gz 
hosts.gz: gzip compressed data, was "hosts", from Unix, last modified: Thu Jul  1 15:28:53 2010

# file -i hosts.gz 
hosts.gz: application/x-gzip

# file -z hosts.gz 
hosts.gz: ASCII English text (gzip compressed data, was "hosts", from Unix, last modified: Thu Jul  1 15:28:53 2010)


今日はこんなところで。