About nixCraft

Topics

Debian Linux remove unwanted packages and files to reclaim disk space

Posted by Vivek Gite [Last updated: December 14, 2007]

After few months or years later, you will notice unnecessary files, libraries and/or documentation eating up your disk space under Debian Linux. Try the following tips to free up disk space:

Remove cached .deb files

When you run apt-get command, it downloads and caches the package in /var/cache/apt/archives directory.
# cd /var/cache/apt/archives
# du –ch

Output:

8.0K    ./partial
838M    .
838M    total

Next remove all cached *.deb files:
# rm –f *.deb

Remove Orphaned package

deborphan command finds packages that have no packages depending on them. The default operation is to search only within the libs and oldlibs sections to hunt down unused libraries.

Following command displays Orphaned package list:
$ deborphan -sz
Where,

You can remove orphaned package with apt-get remove command:
# apt-get remove packagename
Alternatively, remove all orphaned package in one command:
# apt-get remove $(deborphan)
Better try:
# apt-get remove --purge $(deborphan)

If you find command line hard to use try orphaner command which is nothing but a neat frontend for deborphan displaying a list of orphaned packages with dialog or whiptail. Packages may be selected for removal with apt-get which is then called to do the work. After removal a new list of orphaned packages is gathered from deborphan. The program ends when either "Cancel" is pressed or no package is marked for removal.
# orphaner


(Fig 01: orphaner command in action )

However some packages are important and if you want to keep them forever, use editkeep command which is a frontend for deborphan displaying a list of orphaned packages (-a for all-sections is implied) and packages which are tagged to never been shown using dialog or whiptail:
# editkeep

cruft command

cruft is a program that goes over the Debian packaging system's database, and compares the contents of that with the files actually on your system, and produces a summary of the differences. For example, you can clean spool with following command:
# cruft –k

Read the cruft man page for advance usage.

Remove log files

Backup log files and remove them from /var/log directory. To truncate log file you can run for loop:
# cd /var/log/squid
# for i in *; do >$i; done

Also, consider rotating log files using logroate facility.

See also:

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Doug Says:

    One point - you don’t have to manually remove the debs in Apt’s download archives. The command ‘apt-get clean’ will remove all the package files in /var/cache/apt/archives for you. Better. ‘apt-get autoclean’ will remove just those debs that can no longer be downloaded, and so are obsolete.

  2. Badar Says:

    Thanks a lot for this.. i was desperately needing it.

  3. dot tilde dot Says:

    is there any difference between

    rm -rf /var/cache/apt/archives/* and
    apt-get clean ??

    .~.

  4. dot tilde dot Says:

    aah. should have read the comments, too.

    blushingly,
    .~.

  5. dan Says:

    also, to got reading every package description and then being asked to purge it or not, use the following:


    # for file in `deborphan`; do aptitude search "^$file$" && aptitude purge "$file";done;

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.