Useful apt (dpkg) commands [closed]
Some command I often use:
to see dependencies and reverse dependencies:
apt-cache [--important] [--installed] [--recurse] depends $package
apt-cache rdepends $package
To remove a package, all autoremove packages, and all related config files:
sudo apt-get --purge --auto-remove purge $package
To see actual apt
configuration options:
apt-config dump | less
To modify an option on the command line
$ apt-config dump | grep -i recommend
APT::Install-Recommends "1";
$ sudo apt-get -o APT::Install-Recommends="0" install $package
This was just and example of specifying APT options through the command line, to avoid installing recommended packages, you can use:
sudo apt-get --no-install-recommends $package
To see all local/obsolete packages:
aptitude search ~o
To see removed packages with residual configuration:
aptitude search ~c
and to remove them
sudo aptitude purge ~c
To obtain a list of all installed packages (dpkg -l
can sometimes give truncated columns output)
dpkg --get-selections | awk '{ print $1 }'
or
dpkg-query -Wf '${Package}\n' # other fields available, see man page
To dissasemble, modify then riassemble a package
dpkg-deb -x file.deb ./dir
cd dir
dpkg-deb -e ../file.deb
# apply your modification, then...
cd ..
dpkg-deb -b dir file-new.deb
Two that I use a lot are:-
apt-get autoremove <packagename>
Which will remove the package and any unused dependancies, which is useful if you try an app out, then decide you don't need it, and want the cruft to be removed also.
dpkg -S /path/to/file
Which tells me which package a file was installed with.
Finally, one more..
dpkg -l <packagename> | grep ^ii
Lists packages but only those that have the status ii which means they're installed, so it wont show stuff I've removed.
If you wish to get the package name for a file which was not installed (dpkg -S
, but for non-installed packages), install apt-file
and run:
apt-file search /path/to/file
View the ChangeLog of a package
$ aptitude changelog <pkgname>
Example:
$ aptitude changelog sudo
sudo (1.7.0-1ubuntu2.4) karmic-security; urgency=low
* SECURITY UPDATE: properly handle multiple PATH variables when using
secure_path in env.c
- Adapted http://www.sudo.ws/repos/sudo/raw-rev/a09c6812eaec
- CVE-2010-1646
...
Install apt-file, then run sudo apt-file update
. You can now search for files in packages that you don't even have installed.
Also handy if you need to know information about packages in other versions of Ubuntu is rmadison, which is in the devscripts package. Provide it with a package name as an argument and it will tell you what versions of that package exist in every current Ubuntu version, and what repository section the package is in.
Example:
[bnrubin@server:~/]$ rmadison cowsay
cowsay | 3.03-8 | dapper/universe | source, all
cowsay | 3.03-9 | hardy/universe | source, all
cowsay | 3.03-9.2 | jaunty/universe | source, all
cowsay | 3.03-9.2 | karmic/universe | source, all
cowsay | 3.03-9.2 | lucid/universe | source, all
cowsay | 3.03+dfsg1-2 | maverick/universe | source, all
cowsay | 3.03+dfsg1-2 | natty/universe | source, all
To get list commands starts with 'apt-' you do the following. open a terminal and type 'apt-' and press TAB key twice this will list all commands starts with 'apt-'.
Sample output:
apt-add-repository apt-extracttemplates apt-key
apt-cache apt-file apt-mark
apt-cdrom apt-ftparchive apt-sortpkgs
apt-config apt-get
To get a detailed information you can check man page of that a specific command
eg: man apt-get