While I was writing up a tag information for rename, I tried to look up with which package the rename command was installed. I ran the usual dpkg -S (also mentioned in this question):
$ which rename
/usr/bin/rename
$ dpkg -S $(!!)
dpkg-query: no path found matching pattern /usr/bin/rename
I normally don't install commands by hand in /usr/bin, and on the other machines I have access to, rename is installed as well. My first suspicion was that this command was copied there in some post-install step of some package.
Then I did an ls -l /usr/bin/rename and found that the rename command did happen to be a link. I tried dpkg -S on the link target (/etc/alternatives/rename), but dpkg -S /etc/alternatives/rename did not give a package name either.
After some further searching I found that real executable target of that link chain is /usr/bin/prename and there is a bug report for dpkg -S behaviour of not following symlinks. That report is from 2003 and I could not find any option to follow symlinks for dpkg and that issue doesn't seem likely to be resolved.
How can I easily find the package that contains the "real" executable in case the command is a symlink?
dpkg -Sdoesn't follow symlinks. There are plenty of packages in which a symlink is installed in a different package than the target, with different meanings./sbin/init -> /lib/systemd/systemdis installed bysystemd-sysv, notsystemd;/usr/include/asmis installed bygcc-multilibnot whatever arch-specific package, etc.However, it does make sense that symlinks through
– o11c Oct 03 '14 at 06:27/etc/alternativesshould be followed.issueon purpose although the original called ig a bug report. A suspect is not necessary a criminal :-). An extradpkgoption to follow symlinks would be nice though as that could more easily both show the package that install the symlink (if any) as well as the "real" target. Some more intelligent behaviour around symlinks managed byupdate-alternativewould certainly be appropriate, especially as that command is part of thedpkgpackage. – Anthon Oct 03 '14 at 06:58