Linuxコマンド【 strings 】バイナリファイルの中身を確認する
当ページのリンクには広告が含まれています。
スポンサーリンク
stringsコマンドは、テキストファイル以外のバイナリファイルやデータファイルの中身を確認するためのコマンドです。
stringsコマンド
書式
strings [オプション] ファイル
指定したファイル中の表示可能な文字列を標準出力に表示します。バイナリファイルやデータファイルの内容を判断するために用います。
オプション
| -f | 出力文字列の前にファイル名を表示します。 |
| -n 数値 | 指定した数値以上の長さを文字列のみを出力します。デフォルトは、4です。 |
使用例
「lessコマンド」で、バイナリファイルを閲覧しようとすると、以下のように「... may be a binary file. See it anyway? (バイナリファイルだけど中身みる?)」というメッセージが表示されます。
# less /sbin/mkfs "/sbin/mkfs" may be a binary file. See it anyway?
「y」と入力すると……。以下のように文字化けします。
^?ELF^B^A^A^@^@^@^@^@^@^@^@^@^B^@>^@^A^@^@^@X^M@^@^@^@^@^@@^@^@^@^@^@^@^@<88>!^@^@^@^@ ^@^@^@^@^@^@@^@8^@ … 略 …
こんなときにstringsコマンドを使います。ファイルの全容はわからないものの、かなり多くの文字列を拾うことができるので、内容を判断する大きな手がかりになります。
# strings /sbin/mkfs
/lib64/ld-linux-x86-64.so.2
__gmon_start__
libc.so.6
__printf_chk
exit
setlocale
optind
perror
dcgettext
putchar
… 中略 …
Usage: %s [options] [-t type fs-options] device [size]
Options:
-t, --type=TYPE file system type, when undefined ext2 is used
fs-options parameters to real file system builder
device path to a device
size number of blocks on the device
-V, --verbose explain what is done
defining -V more than once will cause a dry-run
-V, --version output version information and exit
-V as version must be only option
-h, --help display this help and exit
For more information see mkfs(8).
PATH=/sbin:/sbin/fs.d:/sbin/fs
%s (%s)
util-linux 2.20.1