Know more about your installed Debian Packages

Here you will find all the commands which will tell you about your debian packages.

1. Now, if you are looking whether you’ve downloaded packages or not , then try these commands:

apt-cache search 'foo*'

That is how you tell apt to search the packages you’ve downloaded.

2. Another command which do the same in some different way is:

dpkg-query -l 'foo*'

3. Now, if you want to see the description of your package, use something like this:

apt-cache show postgresql

This displays what the package is designed to do, version info and so forth.

4. Now, if you are wondering which all packages are installed in your system, run this on your terminal:

dpkg -l

5. Now if you are thinking of viewing all installed packages along with there description, use this one:

dpkg -l \*
dpkg -l '*'

These list all packages. (Without the star glob, dpkg only lists installed packages.)

5. To Finds installed packages marked to be purged, put this on your terminal:

dpkg -l \* | grep ^pi

6. This lists packages marked for installation, that aren’t installed yet.

dpkg -l '*' | grep "^i[^i]"
dpkg -l \* | grep '^[^i]i'

7. And if you are looking for installed package with all its files(with full paths), then how about this:

dpkg -L php5
gurpinder@gurpinder:~$ dpkg -L php5
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/php5


Debian Package Structure

One can find lots of .deb files in directory ‘/var/cache/apt/archives/.

From there I'm taking package “youtube-dl_2012.02.27-1ubuntu0.1_all.deb” to explain structure of Debian package.

As you can see, the package further contains two folders: DEBIAN and usr.

DEBIAN has two files:md5sums and control.

'md5sums' contains for each file in data.tar.gz the md5sum.

The MD5 protection that exists in dpkg is really only useful for accidental corruption, and not necessary to protect the installation path.

You might be interested in the debsums package, but since it uses MD5s, it also is only useful for checking for accidental corruption.

In our example the content looks like this:

....................................................................................................................................

43678cad6a1b4ff3330c2fada3206894 usr/bin/youtube-dl 
2fcb94a9ce36afaeecf4265b19244727 usr/share/doc/youtube-dl/NEWS.Debian.gz 
77da787ff167347b77383440c31891c1 usr/share/doc/youtube-dl/changelog.Debian.gz 
705df117892f3fd870fb153fb3a530a8 usr/share/doc/youtube-dl/copyright 
33ccd4dcbefa3eb9daf7d3774d7734fa usr/share/man/man1/youtube-dl.1.gz

.............................................................................................................................................

Control file : Each Debian package contains the master `control' file, which contains a number of fields, or comments when the line starts with '#'. Each field begins with a tag, such as Package or Version (case insensitive), followed by a colon, and the body of the field. Fields are delimited only by field tags. In other words, field text may be multiple lines in length, but the installation tools will generally join lines when processing the body of the field

Here are contents of control file from my example:

Package: youtube-dl 
Version: 2012.02.27-1ubuntu0.1 
Architecture: all 
Maintainer: Ubuntu Developers  
Installed-Size: 205 
Depends: python (>= 2.5) 
Recommends: ffmpeg, ffmpeg (>= 4:0.6) | ffprobe, rtmpdump 
Section: web 
Priority: extra 
Homepage: http://rg3.github.com/youtube-dl/ 
Description: downloader of videos from YouTube and other sites 
 youtube-dl is a small command-line program to download videos from 
 YouTube.com and other sites that don't provide direct links to the 
 videos served. 
 . 
 youtube-dl allows the user, among other things, to choose a specific video 
 quality to download (if available) or let the program automatically 
 determine the best (or worst) quality video to grab. It supports 
 downloading entire playlists and all videos from a given user. 
 . 
 Currently supported sites are: CollegeHumor, Comedy Central, Dailymotion, 
 Facebook, Metacafe, MyVideo, Photobucket, The Escapist, Vimeo, Yahoo!, 
 YouTube, blip.tv, depositfiles.com, video.google.com, xvideos, Soundcloud, 
 InfoQ, Mixcloud, OpenClassRoom. 
Original-Maintainer: Rogério Brito 

............................................................................................................................................

'man deb-control' has more information about it.

'postinst' and 'prerm' files are not mandatory for your first package. But every proper official Debian package has them for good reasons.

‘prerm’ and ‘postinst’ seem to take care of removing old documentation files and adding a link from doc to share/doc.

Here are contents of prerm file from package “python-apt_0.8.3ubuntu7.1_i386.deb”.

……………………………………………………………………………………………………………………….

#!/bin/sh
set -e

# Automatically added by dh_python2:
if which pyclean >/dev/null 2>&1; then
pyclean -p python-apt
else
dpkg -L python-apt | grep \.py$ | while read file
do
rm -f "${file}"[co] >/dev/null
done
fi

# End automatically added section

……………………………………………………………………………………………………………………………….

Debian Packages

Here are my notes about Debian packages.

Now, what is a  Debian package?

Package contain all the files which are necessary to implement set of commands or features.

A Debian package, or a Debian archive file, contains the executable files, libraries, and documentation associated with a particular suite of program or set of related programs.

According to wikipedia, ” Debian packages are standard Unix ar archives that include two tar archives optionally compressed with gzip (zlib), Bzip2, lzma, or xz (lzma2): one archive holds the control information and another contains the program data”.

Here I would mention meaning of various terms used in wiki definition:

  • ar :   archiver or ar is a Unix utility that maintains groups of files as a single archive file (file  composed of one or more computer files).
  • tar: Initially, tar archives were used to store files  on magnetic tape. The name “Tar” comes from this use; it stands for tape archiver. Despite the utility’s name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives).

  • gzip: gzip is a software application used for file compression and decompression.
  • bzip2 : is a free and open source file compressor.

  • Lzma: The Lempel–Ziv–Markov chain algorithm (LZMA) is an algorithm used to perform lossless data compression.

dpkg is used for handling debian packages. dpkg is used to install, remove, and provide information about .deb packages.

Debian Package has a filename that ends in .deb.

There are two types of Debian packages:

  • Binary packages  : It is a type of ad-hoc packaging (built sysytem specific). So such packages are more likely to fail to operate when target system diverges from original environment from where they were built . They are usually distinguished by having a ‘.deb’ file extension.

  • Source packaging: It can be built to produce “binary ” packages on any other machine. They consist of a .dsc file, .orig.tar.gz file and .diff.gz file.

Meaning of  unknown, install, remove, purge and hold in the package status

  • unknown – the user has never indicated whether he wants the package
  • install – the user wants the package installed or upgraded
  • remove – the user wants the package removed, but does not want to remove any existing configuration files.
  • purge – the user wants the package to be removed completely, including its configurationfiles.
  • hold – the user wants this package not to be processed, i.e., he wants to keep the current version with the current status whatever that is.

Installing  a source package

Debian packages cannot be actually installed, they are just unpacked in whatever directory you want to build the source package.

One can download the source package by running the following command:

apt-get source "packagename"