Find out which installed file belongs to which package in Fedora and Debian

I was looking for a binary to know which package it was installed, in this case the mail application.

For Debian:
dpkg --search $(readlink -m $(which mail))
bsd-mailx: /usr/bin/bsd-mailx

For Fedora:
$ rpm -qf $(readlink -m $(which mail))

The 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.
The 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.
The -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 rpm -qf.

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *