Man Page – How to Know if It’s the Correct One

man

For example,

[fakename]$ type echo
echo is a shell builtin

But man echo gives me the GNU coreutils version of echo. What's the easiest way to tell if the man page I'm looking at is the correct one, i.e the one for the utility I'd get if I directly invoked it?

Best Answer

You don't, really. Not without knowledge external to the man page.

In the case of echo (and printf, and test, ...), it's often a shell builtin, so you'll need to know that and read the shell's documentation. (And echo is notoriously different in different implementations, use printf instead.)

In most, if not all shells, you can find if something is a builtin with type command, e.g. type echo will print echo is a shell builtin. (type is specified by POSIX but e.g. fish supports it too, as non-POSIXy as it is.) In Bash, you'd then read man bash, the online documentation, or use the builtin command help (which is specific to Bash, and which you need to know exists).

Even if the command is not a builtin, it's possible that there are several commands with the same name, rename being a famous example (see Why is the rename utility on Debian/Ubuntu different than the one on other distributions, like CentOS?). Now, your OS should have the correct man page for the actually installed utility, and e.g. in Debian, the "alternatives" system updates the corresponding man pages also when the command alternatives are changed. But if you read an online man page, you'll need to be aware of it.

Many utilities have a command line option like --version which might tell you what implementation that command is. (But not nearly all utilities have it. I think it's a GNUism originally, so GNU utilities have it, as well as those that happened to copy the custom.) In the case of rename, it happens to work in telling two different implementations apart:

debian$ rename --version
/usr/bin/rename using File::Rename version 0.20
centos$ rename --version
rename (util-linux-ng 2.17.2)

Besides that, your system might have an alias or a function with the same name of a utility, usually to modify the behaviour of the utility. In that case, the defaults presented in a man page might not apply. Aliases for ls are common, as are aliases adding -i to rm or mv. But type foo would also tell you if foo is an alias or function.

Related Question