9

I've known about apt-cache for quite some time, but only yesterday stumbled on apt-file.

My question is, given this kind of output from the two...

ttsiod@avalon ~
$ apt-cache search setxkb
x11-xkb-utils - X11 XKB utilities
xfce4-xkb-plugin - xkb layout switch plugin for the Xfce4 panel

ttsiod@avalon ~
$ apt-file find setxkb
fish: /usr/share/fish/completions/setxkbmap.fish
fish: /usr/share/fish/functions/__fish_complete_setxkbmap.fish
x11-xkb-utils: /usr/bin/setxkbmap
x11-xkb-utils: /usr/share/man/man1/setxkbmap.1.gz
xmanpages-ja: /usr/share/man/ja/man1/setxkbmap.1.gz
zsh: /usr/share/zsh/functions/Completion/X/_setxkbmap
zsh-beta: /usr/share/zsh-beta/functions/Completion/X/_setxkbmap
zsh-common: /usr/share/zsh/functions/Completion/X/_setxkbmap

...why would one bother with apt-cache? Isn't apt-file superior in every way?

I am probably missing something.

EDIT: The reason I am asking is because apt-file reported MORE packages than apt-cache. I only use apt-cache for the use case "I need tool/manpage/whatever named foo - which packages contain foo?" and it seems that apt-file seems to do everything apt-cache does, but better - it reports more packages (apt-cache MISSES some), and it also shows the filenames involved.

4
  • 4
    They perform two completely separate tasks. The apt-cache search function is looking for packages within repositories. apt-file find is looking for files within your currently installed packages. Commented Feb 10, 2014 at 10:55
  • I think that both apt-cache and apt-file don't look at the currently installed packages - they look at all of them. As you can see in the cmd above, apt-file in fact reported MORE matches than apt-cache (and I definitely don't have "fish" installed) - hence my question, about why one would prefer apt-cache instead of apt-file. Commented Feb 10, 2014 at 11:00
  • That depends on how the apt-file cache was built. By default it only builds a cache of packages that are installed. It has other options that lets it get contents from apt-sources. Commented Feb 10, 2014 at 11:05
  • I installed it (with "apt-get install apt-file") and then used "apt-file update". I used no custom options... and the manpage for update says: "Resynchronize the package contents from their sources. The lists of the contents of packages are fetched from the locations specified in /etc/apt/sources.list". Commented Feb 10, 2014 at 11:13

1 Answer 1

12

apt-cache queries a database of available packages and their metadata (installation source, version, dependencies, description, etc.).

apt-file queries a database of available packages and the files they contain.

The only information in common between these databases is that they both list available package names.

3
  • The reason I am asking is because apt-file reported MORE packages than apt-cache. I only used apt-cache for the use case "I need tool/manpage/whatever named foo - which packages contain foo?" and it seems that apt-file seems to do everything apt-cache does, but better - it reports more packages (apt-cache MISSES some), and it also shows the filenames involved. Commented Feb 11, 2014 at 13:19
  • @ttsiodras apt-cache search searches package names and descriptions. apt-file search searches the list of file names. So if you're looking for the package containing a command with a certain name, apt-file has the information. If you're looking for a package about a certain topic, apt-cache has the information. Commented Feb 11, 2014 at 14:32
  • Thanks, since I am always looking for packages based on contained files, indeed I was using the wrong tool. apt-file from now on! Commented Feb 11, 2014 at 14:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.