I was looking for a binary to know which package it was installed, in this case the mail application.
dpkg --search $(readlink -m $(which mail))
$ rpm -qf $(readlink -m $(which mail))
which mail just tells me where the mail application is in the path.
The $(…) invokes command substitution in a sub shell, which means that the commands in the brackets will be run first and the result will be passed back.
readlink command will print value of a symbolic link or canonical file name which means “tell me what the original file name is even if the application points to a symlink.
-m option will canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence, which means it will keep following the symlink chain to the end regardless of whither the symlinks are bad or not.
All that will give you the path to the actual application you are interested in.
Then you pass it to your package manager to identify which package has installed that application.
In Debian it’s
dpkg --search and in Fedora it’s