Is this study guide wrong about commands for determining file types?

Yes it seems like your book is wrong.

The file command tells what kind of file it is. From the man file: "file -- determine file type".
A few examples:

$  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)

The type command is used to tell if a command is built in or external:

$ type file
file is /usr/bin/file
$ type type
type is a shell builtin

The file type is normally determined with file. Its man states:

file — determine file type

But you can also to certain extent use type. Compare the two listings below for:

  • script.pl, a Perl script
  • not_a_script, an empty file

Here's one for the script:

$ 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

And here's one for the empty file:

$ 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

As you can see, type can determine if a file is executable. Is that a "determination of file type" or not? Well... In a different way to what file provides. The description of the type builtin in Bash's man is as follows:

type [-aftpP] name [name ...]

With no options, indicate how each name would be interpreted if used as a command name.

The correct answer to the question in the book should be in my opinion file, because that's what its man says, and that's what passing tests is about. Or in other words, my first choice is file.

Tags:

Linux

Bash