If you are on a Debian based distribution, you can use the package manager to figure it out:
$ dpkg -S '*bin/man'
man-db: /usr/bin/man
This tells us man-db is the package which owns /usr/bin/man.
$ dpkg -l man-db
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii man-db 2.10.2-1 amd64 tools for reading manual pages
Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.
dpkg-query can be used to extract the version:
$ dpkg-query -W -f '${Version}\n' man-db
2.10.2-1
Putting all this together:
$ dpkg-query -W -f '${Version}\n' $(dpkg -S '*bin/man' | cut -d: -f1)
2.10.2-1
Or a function which could go into .bashrc:
ver() {
package=$(dpkg -S "*bin/$1" | cut -d: -f1)
version=$(dpkg-query -W -f '${Version}' "$package")
printf "%s\n" "$version"
}
ver man
2.10.2-1
(Behind the scenes, dpkg -S is really dpkg-query -S, but dpkg-query -S can't be combined with -W -f.)