Remove packages by pattern on debian and based systems

sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this.
Sample Output
kelevra@lab:~$ sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python-renderpm libgtop2-common xsane libmagick++10 libplot2c2 libcamel1.2-14 python-qt4-common python-reportlab-accel
  libcairomm-1.0-1 libglibmm-2.4-1c2a pstoedit python-qt4 libpangomm-1.4-1 python-qt4-dbus python-sip4 libedataserver1.2-11
  libgtkmm-2.4-1c2a libwmf-bin xsane-common libgtop2-7 imagemagick python-elementtree perlmagick python-reportlab
  libpstoedit0c2a
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  cheese* gksu* gnome-keyring* gnome-mime-data* gnome-mount* hplip-gui* inkscape* libbonoboui2-0* libebook1.2-9*
  libeel2-2.20* libgksu2-0* libgnome-keyring0* libgnome-menu2* libgnome2-0* libgnome2-common* libgnomecanvas2-0*
  libgnomecanvas2-common* libgnomeui-0* libgnomeui-common* libgnomevfs2-0* libgnomevfs2-common* libgnomevfs2-extra*
  libgtkhtml3.14-19* libgtkhtml3.16-cil* libpam-gnome-keyring* monodoc-browser*
0 upgraded, 0 newly installed, 26 to remove and 0 not upgraded.
After this operation, 100MB disk space will be freed.
Do you want to continue [Y/n]?

-4
By: kelevra
2009-04-28 10:34:42

These Might Interest You

What Others Think

a command every debian user running gnome should use :)
GinoMan2440 · 477 weeks and 5 days ago
and ubuntu!
GinoMan2440 · 477 weeks and 5 days ago
except you also want to add... apt-get install kde
GinoMan2440 · 477 weeks and 5 days ago
hehe, I prefer lite window managers, but I think that is very useful when you are just testing other apps ;)
kelevra · 477 weeks and 5 days ago
I grow weary of the kde evangelism going on in the last couple days. PS- you can use apt-get autoremove --purge all in one go. No need for the second apt-get autoremove command ;)
linuxrawkstar · 477 weeks and 5 days ago
There are virtual packages that just contain dependencies for just what you're trying to do manually. I prefer doing this inside aptitude, where I can interactively see what's about to be removed, etc. This is especially useful when there are broken packages, or the dependencies have changed as is sometimes the case on a debian testing system.
bwoodacre · 477 weeks and 5 days ago
apt-get remove --purge gnome~n http://askubuntu.com/questions/62595/how-to-use-wildcards-with-aptitude
unixmonkey8034 · 280 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: