はい、あなたの本は間違っているようです。
file
コマンドは、ファイルの種類を示します。 man ファイルから:「ファイル -- ファイルの種類を決定する」。
いくつかの例:
$ file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=ecc4d67cf433d0682a5b7f3a08befc45e7d18057, stripped
$ file activemq-all-5.15.0.jar
activemq-all-5.15.0.jar: Java archive data (JAR)
type
command は、コマンドが組み込みか外部かを判断するために使用されます:
$ type file
file is /usr/bin/file
$ type type
type is a shell builtin
ファイルタイプは通常 file
で決定されます .その man
状態:
file — ファイルの種類を決定する
ただし、ある程度 type
を使用することもできます .以下の 2 つのリストを比較してください:
script.pl
、Perl スクリプトnot_a_script
、空のファイル
これがスクリプトの 1 つです:
$ ls
script.pl
$ file script.pl
script.pl: Perl script text executable
$ type script.pl
bash: type: script.pl: not found
$ type ./script.pl
./script.pl is ./script.pl
そして、ここに空のファイルの 1 つがあります:
$ ls not_a_script
not_a_script
$ file not_a_script
not_a_script: empty
$ type not_a_script
bash: type: not_a_script: not found
$ type ./not_a_script
bash: type: ./not_a_script: not found
ご覧のとおり、type
ファイルが実行可能かどうかを判断できます。それは「ファイルタイプの判別」ですか?ええと... file
とは別の方法で 提供します。 type
の説明 Bash の man に組み込まれているのは次のとおりです:
タイプ [-aftpP] 名前 [名前 ...]
オプションなしで、コマンド名として使用された場合に各名前がどのように解釈されるかを示します。
この本の質問に対する正しい答えは、私の意見では file
でなければなりません。 、それがその man
であるためです それがテストに合格することです。つまり、私の最初の選択肢は file
です .