+3  A: 

Debian does that via the website:

  • search the Packages page under Search contents of packages
  • the answer in this example
  • options selected where 'packages that contain files whose name contain the keyword' for the unstable distribution (as it is the largest) on 'any' architecture

Ubuntu probably does something similar but I don't know the website / launchpad that well.

You could also fetch the index file ftp://ftp.us.debian.org/debian/dists/sid/Contents-i386.gz but as it changes frequently the website option is probably more convenient.

Dirk Eddelbuettel
I'll take this - Googling "search contents of packages" helped me also get http://packages.ubuntu.com/, http://packages.opensuse-community.org/, andhttp://rpm.pbone.net/
ctd
Yup -- packages.ubuntu.com is correct for Ubuntu.
Dirk Eddelbuettel
A: 

There is many other tools to do this check this great page for this : http://www.debianhelp.co.uk/findfile.htm It is for debian or Ubuntu

sohaibafifi
A: 

If you have a file on your machine, and you want to know which package is responsible for it, then (on Debian & Ubuntu) it's...

$ dpkg -S FILENAME
alex tingle
True yet irrelevant -- OP wrote "and it's nowhere on my system".
Dirk Eddelbuettel
+2  A: 
$ sudo apt-get install apt-file
$ sudo apt-file update
$ apt-file search libX11.so.6

apt-file will let you list and search the contents of packages whether or not they are installed on your system.

$ sudo apt-get install auto-apt
$ sudo auto-apt update
$ sudo auto-apt updatedb
$ sudo auto-apt update-local
$ auto-apt run ./configure

For even more automation, auto-apt will detect attempts to access non-existent files and automatically prompt you to install the packages providing those files.

ephemient