38

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?

3

4 Answers 4

39

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

0
23

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]
1
  • 2
    Simply dpkg -S [binary-name] works for me (on Ubuntu 16.04).
    – waldyrious
    May 30, 2018 at 9:06
5

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.

1
  • 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, 2018 at 14:37
3

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
/usr/bin/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

1
  • 3
    Poor man's apt-file: dpkg -S rename| grep -F $(which rename)
    – alexyorke
    Aug 17, 2018 at 14:57

Not the answer you're looking for? Browse other questions tagged .