I'm answering a question with a suggestion to use rename, and I realize I don't know what package it comes from (as part of the answer, I imagine saying something like "if you don't have rename, it's installed as part of [package]").

man rename tells me to SEE ALSO: mv(1), perl(1) - so my first thought is that it was installed with perl.

A related answer, how to tell what was installed as part of a package, helps me figure out that the perl package includes prename but not rename - and it turns out that my /usr/bin/rename points to /etc/alternatives/rename which points to /usr/bin/prename

So this is still kind of confusing. Did /etc/alternatives/rename point somewhere else before I installed perl? Is there a general way to tell which package something comes from?


install apt-file

$ sudo apt-get install apt-file

update apt-file

$ sudo apt-file update

search the package a file belongs to

$ apt-file search filename

find path of executable

$ whereis rename
rename: /usr/bin/rename.ul /usr/bin/rename /usr/bin/X11/rename.ul /usr/bin/X11/rename     /usr/share/man/man1/rename.1.gz /usr/share/man/man2/rename.2.gz

search package

$ apt-file search /usr/bin/rename
ladr4-apps: /usr/bin/renamer
util-linux: /usr/bin/rename.ul

the package name is: util-linux

| improve this answer | |

Turns out dpkg-query is good to get information about installed packages, and with the -S [pattern] option will search for packages with files corresponding to [pattern].

dpkg-query -S [filename-search-pattern]
| improve this answer | |
  • Simply dpkg -S [binary-name] works for me (on Ubuntu 16.04). – waldyrious May 30 '18 at 9:06

As of 2018

apt search filename

works for recent Ubuntu and most Debian based distros.

Update May 2018: Apparently no longer working with Ubuntu 18.04.

| improve this answer | |
  • 2
    Really? In Ubuntu bionic, this doesn't seem to search for filenames. $ apt search yields nothing, vs wajig which-package /bin/date which says coreutils: /bin/date – nealmcb May 3 '18 at 14:37

You can try apt-file (it's not part of default installation).

0) Update apt-file database

sudo apt-file update

1) Find binary

$ which rename

2) Find the package

$ apt-file search /usr/bin/rename
util-linux: /usr/bin/rename.ul

And voila -- rename is part of util-linux

| improve this answer | |
  • 2
    Poor man's apt-file: dpkg -S rename| grep -F $(which rename) – alexyorke Aug 17 '18 at 14:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.