I started using DebianLinux in 1995 when I was still fairly new to Unix. I'd run EarthLight on a combination of SunOS and SlackwareLinux boxes for a couple years but hadn't touched Debian. At the time it was a toss up between RedhatLinux and DebianLinux (Slackware and SunOS had to go :-)). I must say I think I chose wisely, I've been very happy with Debian ever since. Below is a collection of some of the commands I've found useful in maintaining my Debian laptops (see ThinkPad390 and ThinkPadT20), desktops and servers.

If you have anything that you think should be added please feel free to email me, I'm sure there are plenty more tricks out there that I don't know about.

-- AdamShand

See also: DebianLinux, UsingRpm, DebianKernelDpkg

Files and Directories

/etc/apt/apt.conf
This file isn't created by default but is where you can put parameters to tweak the way that apt behaves. There is more information about it in the apt.conf man page and there is an example file in /usr/share/doc/apt/examples.
/etc/apt/sources.list
This is where you specify where apt gets it's package lists and the actual packages. typically you would have these three lines though you can add many more for other apt repositories..

deb http://http.us.debian.org/debian stable main contrib non-free
deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free
deb http://security.debian.org stable/updates main contrib non-free

/var/cache/apt
This is where apt keeps the Packages.gz files and the actual packages which you tell it to download. there is a subdirectory called partial which is where interrupted or files which are currently being downloaded are kept.
/var/lib/dpkg/info
Where all debian package pre and post install and remove scripts are stored. This is useful for when a package bombs and you need to debug an install script or just want to better understand what a package does when you install it. Other package data is stored here as well like md5 check sums list files etc.

Using Dpkg

dpkg -i <package file>
Will install the package.
dpkg -r <package name>
Removes the package, but not the config files. If another package depends on it, the command will fail with an error telling you what the problem is.
dpkg --purge <package name>
Removes the package and the config files (good if you screwed something up and want a fresh start at making it work). If another package depends on it, the command will fail with an error telling you what the problem is.
dpkg -l
This will show you all the packages currently installed on your system. It also shows you their installed state, a leading "ii" means that it's all good.
dpkg -l netscape*
As above but you can use wild cards. depending on your shell, and how it's setup, you may have to backslash wild cards in order to avoid them being expanded (i don't have to using bash). i have found though that if i want to use multiple wild cards (eg. "*nets*") i need to quote it.
dpkg -L <package name>
This will show you the contents of a package (it has to be installed).
dpkg -S file or dpkg -S /path/to/file
This will show which package any matching file belongs to (remember that if you don't specify a full path, a filename can be ambiguous). One thing that's annoyed me before is if you remove a package with 'dpkg -r ' (which doesn't remove config files) and then do a 'dpkg -S 'on one of the remaining config files, it will show as not belonging to any package.
dpkg --ignore-depends <action> <package name>
Allows you to perform an action (eg. '-i') to a package even though some dependency isn't being met correctly. b\Be very careful you can break a lot of stuff doing this. A couple years ago I'd find that I needed to do this every once in a while to get out of incorrect package dependencies. These days just using apt and being selective about what I upgrade to in the unstable tree seems to do me just fine almost all of the time. It's a good trick to have though in case you get stuck.
echo "<package name> hold" | dpkg --set-selections
I haven't had to use this yet but it's supposed to allow you to put a package on hold so that apt won't upgrade it.
dpkg-reconfigure <package name>
If the package uses debconf (a lot don't but more and more do) it allows you to go through the initial config process without purging and re-installing.
dpkg-repack <package name>
Allows you to create a debian package from the installed files. iIve used this when I don't have net access and want to install a package I have on one computer onto another computer that i'm helping a friend setup (requires dpkg-repack package).
dpkg-scanpackages . /dev/null | gzip -c > Packages.gz
Makes a debian style Packages.gz file so you can setup your own apt repository. I haven't used this yet but I probably will soon (requires dpkg-dev package).

Using Apt

apt-get install <package name>
This will download and install the package and any other packages it requires. If other packages are required to successfully install it will prompt you for an "okay" before it actually does it.
apt-get remove <package name>
Removes (eg. 'dpkg -r') the package and any other packages that depend on it. If it's going to remove anything you didn't explicitly request it to it will prompt you before doing it.
apt-get clean
Removes all downloaded packages from /var/cache/apt/archives, this is a good housekeeping thing to do every once in a while.
apt-get update
Updates apt's knowledge of which packages are available. If you try and install something and get errors saying that the specified package is "not found" this is most likely the cause.
apt-get upgrade
This upgrades to the latest versions of all currently installed packages that are available to you (eg. if you're you have stable specified in your /etc/apt/sources.list file packages from unstable won't be available).
apt-get dist-upgrade
As above but this is for moving from stable to unstable. It's designed to deal more gracefully with problems that can sometimes occur with upgrades between versions (eg. the infamous libc6 upgrade which would break your system if you didn't install the new packages in a certain order).
apt-get build-dep <package name>
Using build-dep causes apt-get to install/remove packages in an attempt to satisfy the build dependencies for a source package.
apt-cache search <string>

Will show any package (and it's short description) which can be found in the packages database which matches <string> in the packages name or description.

apt-cache --names-only search <string>

Will show any package (and it's short description) which can be found in the packages database which matches <string> in packages name only.

apt-cache show <package name>
Will show all the information known about a given package.
apt-get moo

<shhhh> ....

apt-cache showpkg <package name>
This shows all package dependency information for this package, including the sometimes very useful "reverse-provides" which lists packages which depend on it.
apt-get -d install <package name>
Will download all requires packages to /var/cache/apt/archives but won't install them.
apt-get --compile source <package name>
Will download the source package and diffs and compile it into a .deb for you. this requires some of the debian packaging tool packages. You also must have a line in your /etc/apt/sources.list file similar to this:

deb-src http://http.us.debian.org/debian stable main contrib non-free

apt-get -t <release> install <package name>

Used in combination with the Default-Release parameter in your /etc/apt/apt.conf this allows you to list multiple releases (ie. testing and unstable) in your /etc/apt/sources.list file. You can set one as the default and then specifically install from another via this command. See the online tutorial on Apt-Pinning.

console-apt (or aptitude)
Some console based gui's for apt. They do things slightly differently then each other and are nice when you're starting out. I used to use console-apt (aka capt) but haven't used either for quite a while.
apt-listchange <options>
If you set this to work with apt (it'll ask you after you install it) then every time you install a package with apt it will show you what's changed from your old installed version and the newly installed version. On a production system it's often nice to see this info before you actually do the upgrade, there's a command below that will help you with that.
auto-apt
I only just discovered about this, it appears to automate the installation of packages on an "as needed" basis. I don't understand why and how you would do this yet. More as I play with it.
It comes in handy when you

./configure; make; make install :: software from source. Use :: auto-apt run ./configure :: and all things the configure-script is looking for will be downloaded and installed "on-demand" an "just-in-time". To be more precise: the packages containing the missing files will be :: apt-get install :: -ed. After all you continue with :: make :: and :: make install :: as normal.
For further reading see How to install packages "on demand" in the Apt-HOWTO and auto-apt's man-page. -- [^http://www.patrick-willam.de Patrick Willam]

Acquire::http::Proxy "http://ipofproxyserver:port";
Put this in your /etc/apt/apt.conf if you need to use a proxy server with apt.
APT::Default-Release "testing";
Put this in /etc/apt/apt.conf if you have more then one distribution selected (eg. both testing and unstable) in /etc/apt/sources.list. It can be used in combination with 'apt-get -t'.

Other Commands

deborphan
Will show you any packages which are installed which currently nothing depends on anymore. often happens when you install a lot of programs to play with and remove them later (requires deborphan package).
lynx http://master.debian.org/cgi-bin/get-changelog\?package=<options>
Similar to apt-listchanges only you can use this to view the change log of a package which you are considering upgrading to before you actual download and install it with apt. Good for production systems where it pays to be wary of making changes. You can make this a little more convenient by putting something like this in your ~/.bash_profile:

debchg() { [ $# = 1 ] && \
 lynx http://master.debian.org/cgi-bin/get-changelog\?package=$1

dlocate <options>
Dlocate is a woody package which does much of what dpkg does only with a locate database instead of accessing the file system directly. It is thus much faster but not at all necessary.
reportbug <package name>
Think you've found a bug and want to report it, reportbug makes this process a lot easier. When you report a bug please only report bugs which haven't already been reported (reportbug will give you the chance to check) and which you can provide enough information about to be useful (requires reportbug package).
update-rc.d <script name> defaults
Debian uses the /etc/init.d directory to store all the start/stop scripts that various packages and daemons needs. If you install a non-debian program which you need to start at boot time you can use /etc/init.d/skeleton file as a starting point. Now in order to make it start on boot you have to link it, with a special name into each of the /etc/rc[S0-6].d so the system knows what run levels to start/stop it at, update-rc.d is the easy way of doing this. Just run the above command and it will automatically create all the links for you (assuming you want it to start/stop in a fairly normal manner).
update-rc.d -f <script name> remove
Sometimes you want a package installed but you don't want it to run on startup (eg. i normally disable portmap and gpm in this way). Just run the above command and it will automatically remove all the links in /etc/rc[S0-6].d for me.

Useful URLs

Thanks To


CategorySoftware CategoryUnix

UsingApt (last edited 2006-06-16 03:31:08 by AdamShand)