Linux+: Applications 19 – Query Packages with apt-get

J

Jarret W. Buse

Guest
Linux+: Applications 19 – Query Packages with apt-get

With any computer system, Linux being no exception, a user needs to query applications. In Linux, the applications are kept in a 'package' which contains all necessary information to manage the application.

The apt-get command has no ability for querying the package database, so there are two other commands used for querying packages. The commands for querying packages are:

  • apt-cache
  • apt-file
NOTE: If the files are not installed, you can install them with the following commands in the terminal:

apt-cache: sudo apt-get install apt-cache
apt-file: sudo apt-get install apt-file


Queries are done within the file which stores the package information from the repositories. The repository list is updated when the command “sudo apt-get update” is executed. The repository list is stored at /etc/apt-sources.list. The package state is stored at /var/lib/apt/lists/. Each repository has its own file containing a list of packages stored at that repository.An entry example for the Adobe Flash plugin is:

Package: adobe-flashplugin
Priority: optional
Section: web
Installed-Size: 31128
Maintainer: DL-Flash Player Ubuntu <[email protected]>
Architecture: i386
Version: 1:20150512.1-0trusty1
Recommends: adobe-flash-properties-gtk (= 1:20150512.1-0trusty1) | adobe-flash-properties-kde (= 1:20150512.1-0trusty1)
Replaces: flashplugin (<< 6)
Suggests: firefox | chromium-browser, x-ttcidfont-conf, msttcorefonts, ttf-bitstream-vera | ttf-dejavu, ttf-xfree86-nonfree, xfs (>= 1:1.0.1-5), libnspr4-0d, libnss3-1d
Provides: flashplugin-nonfree
Depends: wget, fontconfig, libatk1.0-0 (>= 1.12.4), libc6 (>= 2.11), libcairo2 (>= 1.2.4), libfontconfig1 (>= 2.9.0), libfreetype6 (>= 2.2.1), libgcc1 (>= 1:4.1.1), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.12.0), libgtk2.0-0 (>= 2.24.0), libnspr4 (>= 2:4.9-2~) | libnspr4-0d (>= 1.8.0.10), libnss3 (>= 2:3.13.4-2~) | libnss3-1d (>= 3.12.0~beta3), libpango-1.0-0 (>= 1.14.0), libpangocairo-1.0-0 (>= 1.14.0), libpangoft2-1.0-0 (>= 1.14.0), libstdc++6 (>= 4.3), libx11-6, libxcursor1 (>> 1.1.2), libxext6, libxrender1, libxt6
Conflicts: flashplayer-mozilla, flashplugin (<< 6), flashplugin-downloader, flashplugin-installer, xfs (<< 1:1.0.1-5)
Filename: pool/partner/a/adobe-flashplugin/adobe-flashplugin_20150512.1-0trusty1_i386.deb
Size: 9381908
MD5sum: 67ffa05f36f4f170d21b4aa86c1af5a8
SHA1: d7639a11102a2148a7f61364b55d01055eb93fe4
SHA256: 8af58b3aaf0bff91f017d8528a68a2f2495de3475949d01d157ef4cb813f3511
Description: Adobe Flash Player plugin
Description-md5: 4414ca68dbd37fdc3008c70a8a107946
Npp-File: libflashplayer.so
Npp-Mimetype: application/x-shockwave-flash
Npp-Applications: ec8030f7-c20a-464f-9b0e-13a3a9e97384, 92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a, aa5ca914-c309-495d-91cf-3141bbb04115
Npp-Description: Adobe Flash Plugin (http://www.adobe.com)
Npp-Name: Adobe Flash Plugin


Some basics for searching the cache with apt-cache are the commands:

  • showpkg (package) – shows specific package information of the package name specified
  • search (regex_expression) – searches the repository list for the regex expression given
  • show (package) – similar to the showpkg subcommands

For example, to show all packages in the repository for Adobe, the command used could be: “apt-cache search adobe”. Once a list is given of the packages in the cache which contain the name “adobe”, you can more specific information. One such package name may be “adobe-flashplugin”. To get more information about this entry, use the command: “apt-cache showpkg adobe-flashplugin”.

Using apt-file is similar to apt-cache. The apt-file uses its own cache, but updates it with the repository list at /etc/apt-sources.list. The cache is stored by default at $HOME/.cache/apt-file with fall-back to /var/cache/apt/apt-file. The apt-file cache is stored as compressed files, one per repository. To update the apt-file cache, use the command: “apt-file update”.

NOTE: Searches cannot be made using apt-file until the cache is updated. If the update has not been performed, an error will occur which informs you to perform an update.

To perform a search, use the “search” subcommand. For example, to perform a search of files and their packages which contain the “apt-file” name in the filename, use the command:

apt-file search apt-file

The results would be something similar to :

aide-common: /usr/share/aide/config/aide/aide.conf.d/31_aide_apt-file
apt-file: /etc/apt/apt-file.conf
apt-file: /etc/bash_completion.d/apt-file
apt-file: /usr/bin/apt-file
apt-file: /usr/bin/rapt-file
apt-file: /usr/share/apt-file/apt-file-update.update-notifier
apt-file: /usr/share/apt-file/do-apt-file-update
apt-file: /usr/share/apt-file/is-cache-empty
apt-file: /usr/share/doc/apt-file/README
apt-file: /usr/share/doc/apt-file/changelog.gz
apt-file: /usr/share/doc/apt-file/copyright
apt-file: /usr/share/man/man1/apt-file.1.gz
apt-file: /usr/share/man/man1/rapt-file.1.gz
fish: /usr/share/fish/completions/apt-file.fish
live-build: /usr/share/live/build/hooks/001-update-apt-file-cache.chroot
zsh-common: /usr/share/zsh/functions/Completion/Debian/_apt-file


The output shows “package_name:path_name/file_name”. These are found in the repository cache, but only file names are searched, not folder names.

This can be used to find specific files in the repository and which packages in which they are contained.

To find all of the files contained within the package, you need the package name. For instance, to find all files within the “apt-file” package use the subcommand “list”. For the command “apt-file list apt-file” the results would be:

apt-file: /etc/apt/apt-file.conf
apt-file: /etc/bash_completion.d/apt-file
apt-file: /usr/bin/apt-file
apt-file: /usr/bin/diffindex-download
apt-file: /usr/bin/diffindex-rred
apt-file: /usr/bin/rapt-file
apt-file: /usr/share/apt-file/apt-file-update.update-notifier
apt-file: /usr/share/apt-file/do-apt-file-update
apt-file: /usr/share/apt-file/is-cache-empty
apt-file: /usr/share/doc/apt-file/README
apt-file: /usr/share/doc/apt-file/changelog.gz
apt-file: /usr/share/doc/apt-file/copyright
apt-file: /usr/share/man/man1/apt-file.1.gz
apt-file: /usr/share/man/man1/diffindex-download.1.gz
apt-file: /usr/share/man/man1/diffindex-rred.1.gz
apt-file: /usr/share/man/man1/rapt-file.1.gz


Here, all the files contained in the “apt-file” package are listed to allow you to see what is in the package.

Now, let's look at a real world example. Suppose you look at a system and find a file called “berusky.ini”. To find what package it belongs to, I can run the command: “apt-file search berusky.ini”. I get the result:

berusky-data: /etc/berusky/berusky.ini

Now that I know the package name is “berusky-data”, I can see what other files belong to the package by running the command: “apt-file list berusky-data”. Now, I need to see if “berusky-data” is a dependency of another package. I can use “apt-cache” with the subcommand “rdepends” to find out. The command “apt-cache rdepends berusky-data” shows the following:

berusky-data
Reverse Depends:
berusky


So, the “berusky.ini” file was part of “berusky-data” which was installed by the package “berusky”. I can run the command “apt-cache rdepends berusky” and get:

berusky
Reverse Depends:


So I now know that “berusky” was the main package since no Reverse Depends were found.

Try these tricks out and see what files were installed with which packages and how deep a dependency tree might be in some cases.
 

Attachments

  • slide.jpg
    slide.jpg
    32.9 KB · Views: 50,603

Staff online

Members online


Latest posts

Top