The Issue:

When I type:

dpkg-query -Wf '${Package;-40}${Priority}\n' | sort -b -k2,2 -k1,1

I get a list of all installed packages on my machine, example:

raspberrypi-artwork                     extra
raspberrypi-bootloader                  extra
raspberrypi-ui-mods                     extra
raspi-config                            extra
rpi-update                              extra
sonic-pi                                extra
ssh                                     extra
triggerhappy                            extra
wireless-tools                          extra
xkb-data                                extra
adduser                                 important
apt                                     important
apt-utils                               important
aptitude                                important
aptitude-common                         important
bsdmainutils                            important

I have recently run a script that installed way to many things and now my machine responds with: /usr/bin/mandb: can't write to /var/cache/man/2694: No space left on device (the paths change but it always tells me there is no space left.)

The possible labels I see are:

  • standard
  • extra
  • important
  • optional
  • required

I have uncommitted changes in various repos and I want to be able to push my local changes but I keep getting this error when I attempt to push:

$ git push
fatal: write error: No space left on device
error: Couldn't write .git/refs/remotes/origin/master.lock
error: Cannot update the ref 'refs/remotes/origin/master'.
Everything up-to-date

I should also say that I know everything is not up to date.

The System:

This is on a raspberry pi running "wheezy" raspbian.

The question:

I have several hundred packages installed. How do I remove all packages labeled 'extra'? Is this the best way to free space on my machine? I have uncommitted changes in various repos and I want to be able to push my local changes.

I would also accept an answer that removes everything but required and important. Git is labeled under optional and I would prefer to keep this (though I can always install it again after removing all unneeded packages).

Thanks in advance!!

  • dpkg -C should tell you what packages are in an inconsistent state. If you can put that list in your question it should be helpful. – Faheem Mitha Feb 14 '16 at 22:36
  • First you should check which disks are full an why they are full: check the larges files and the newest files on these file systems. Maybe there are log files that you can clear, core dumps that can be removed or files you copied to the system but don't nee anymore. – miracle173 Feb 14 '16 at 23:32

You can use the following command to purge all optional and extra packages: sudo apt-get --simulate purge $(dpkg-query -Wf '${Package;-40}${Priority}\n' | awk '$2 ~ /optional|extra/ { print $1 }')

The --simulate flag lets you see what will be removed without actually removing everything. Remove the flag to actually uninstall packages.

You will need to reinstall git, as it will be removed along with the other optional and extra packages.

You might need some optional and extra packages, so remove with care. More here: https://askubuntu.com/questions/79665/keep-only-essential-packages


You'd have to check where you run out of space. The df(1) command tells you what filesystems are full.

A common reason for running out of space is large log files (check under /var/log, your system should have commands to clean out stale logs). Note that sort(1) uses temporary files, either in var/tmp or /tmp, if either of those contains too much cruft, it can fail for lack of space.


Since you have aptitude installed, it can help you here. Launch aptitude and limit (shortcut: l) the view to packages matching

~i ~pextra

See the online manual or /usr/share/doc/aptitude/README for a search term reference.

You can now choose to uninstall them all: press - under each top-level heading to mark the packages for uninstallation (keeps configuration files), or _ to mark them for purging (removes configuration files), then g to go ahead. You do get an opportunity to review the list in case you want to keep some of the packages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.