Cleaning up a Ubuntu GNU/Linux system

Sponsored Link
If you want to clean your ubuntu machine you need to follow these simple steps to remove all unnecessary junk files.

Remove Residual Config packages

In Synaptic Package Manger, there is a built-in feature that gets rid of old Residual Config packages. Residual Config packages are usually dependency packages that are left behind after you uninstall a package from your machine. To use this feature, go to System > Administration > Synaptic Package Manager. On the bottom left hand corner of the window,click the Status button. In the list above the Sections, Status, Search, and Custom buttons, you should see the following text

Installed
Installed(auto removable)
Installed(local or obsolete)
Installed(upgradable)
Not installed
Not Installed (Residual config)


Click on the "Residual config" text. (If the "Residual config dialogue does not appear, that means you do not have any Residual Config packages on your machine.

If you want to remove you need to select those packages and click on apply from menu bar Remove packages are in progress

Remove partial packages

This is yet another built-in feature, but this time it is not used in Synaptic Package Manager. It is used in theTerminal. To access the Terminal, go to Applications > Accessories > Terminal. Now, in the Terminal, key in the following command

sudo apt-get autoclean

Remove unnecessary locale data

For this we need to install localepurge.Automagically remove unnecessary locale data.This is just a simple script to recover diskspace wasted for unneeded locale files and localized man pages. It will automagically be invoked upon completion of any apt installation run.

Install localepurge in Ubuntu

sudo apt-get install localepurge

After installing anything with apt-get install, localepurge will remove all translation files and translated man pages in languages you cannot read.

If you want to configure localepurge you need to edit /etc/locale.nopurge

This can save you several megabytes of disk space, depending on the packages you have installed.

Example:-

I am trying to install dicus using apt-get

sudo apt-get install discus

after end of this installation you can see something like below

localepurge: Disk space freed in /usr/share/locale: 41860K

Remove "orphaned" packages

If you want to remove orphaned packages you need to install deborphan package.

Install deborphan in Ubuntu

sudo apt-get install deborphan

Using deborphan

Open Your terminal and enter the following command

sudo deborphan | xargs sudo apt-get -y remove --purge

Remove "orphaned" packages Using GtkOrphan

GtkOrphan (a Perl/Gtk2 application for debian systems) is a graphical tool which analyzes the status of your installations, looking for orphaned libraries. It implements a GUI front-end for deborphan, adding the package-removal capability.

Install GtkOrphan in Ubuntu

First you need to download latest version of GtkOrphan from here using the following command

wget http://ftp.debian.org/debian/pool/main/g/gtkorphan/gtkorphan_0.4.2-2_all.deb

Now you have gtkorphan_0.4.2-2_all.deb package you need to install this using the following command

dpkg -i gtkorphan_0.4.2-2_all.deb

At the time of installation you get the following error

dpkg -i gtkorphan_0.4.2-2_all.deb
Selecting previously deselected package gtkorphan.
(Reading database ... 175891 files and directories currently installed.)
Unpacking gtkorphan (from gtkorphan_0.4.2-2_all.deb) ...
dpkg: dependency problems prevent configuration of gtkorphan:
gtkorphan depends on deborphan (>= 1.7.17); however:
Package deborphan is not installed.
gtkorphan depends on libgtk2-gladexml-perl; however:
Package libgtk2-gladexml-perl is not installed.
dpkg: error processing gtkorphan (--install):
dependency problems -- leaving unconfigured
Errors were encountered while processing:
gtkorphan

You need to use the following command to fix

sudo apt-get -f install

This will complete the installation.Once you finished the installation go to System--->Administration--->Remove Orphaned Packages

Now it will prompt for password enter your password

Once it opens you should see the following screen

Non-orphaned packages list screen shot

GtkOrphan Version Details

Now you need to select the orphaned packaged and click on ok

You need to confirm the removal of packages

Removing Requested packages in progress

Remove Orphan packages using Wajig

simplified Debian package management front end.Wajig is a single commandline wrapper around apt, apt-cache, dpkg,/etc/init.d scripts and more, intended to be easy to use and providing extensive documentation for all of its functions.

With a suitable sudo configuration, most (if not all) package installation as well as creation tasks can be done from a user shell. Wajig is also suitable for general system administration.A Gnome GUI command ‘gjig' is also included in the package.

Install Wajig in Ubuntu

sudo apt-get install wajig

This will complete the installation if you want to open this you can use GUI tool using the following command

gjig

Once it opens you should see the following screen

If you want to view orphan packages select Orphans

If you want to use wajig from the command line you can see the following help

Try the help command for a list of common commands provided by wajig:

$ wajig help

Examples commands include:

$ wajig update (= dselect update)
$ wajig install less (= apt-get install less)
$ wajig new (list new packages since last update)
$ wajig newupgrades (list packages upgraded since last update)
$ wajig toupgrade (list all packages to be upgraded)
$ wajig updatealts editor (update the default "editor")
$ wajig restart apache (restart the apache daemon)
$ wajig listfiles less (list the files supplied by the "less" pkg)
$ wajig whichpkg stdio.h (what package supplies this header file)
$ wajig whatis rats (one line description of the package "rats")
$ wajig orphans (list libraries not required by other pkgs)
For a complete list of available commands increase the level of verbosity of the help command

debfoster -- Keep track of what you did install

debfoster maintains a list of installed packages that were explicitly requested rather than installed as a dependency. Arguments are entirely optional, debfoster can be invoked per se after each run of dpkg and/or apt-get.

Alternatively you can use debfoster to install and remove packages by specifying the packages on the command line. Packages suffixed with a -- are removed while packages without a suffix are installed.

If a new package is encountered or if debfoster notices that a package that used to be a dependency is now an orphan, it will ask you what to do with it. If you decide to keep it, debfoster will just take note and continue. If you decide that this package is not interesting enough it will be removed as soon as debfoster is done asking questions. If your choices cause other packages to become orphaned more questions will ensue.

Install debfoster in Ubuntu

sudo apt-get install debfoster

Using debfoster

to create the initial keepers file use the following command

sudo debfoster -q

you can always edit the file /var/lib/debfosterkeepers which defines the packages you want to remain on your system.

to edit the keepers file type

sudo vi /var/lib/debfoster/keepers

To force debfoster to remove all packages that aren't listed in this list or dependencies of packages that are listed in this list.It will also add all packages in this list that aren't installed. So it makes your system comply with this list. Do this

sudo debfoster -f

To keep track of what you installed additionally do once in a while :

sudo debfoster

xdiskusage -- Check where the space on your hard drive goes

Displays a graphic of your disk usage with du.xdiskusage is a user-friendly program to show you what is using up all your disk space. It is based on the design of the "xdu" program written by Phillip C. Dykstra. Changes have been made so it runs "du" for you, and can display the free space left on the disk, and produce a PostScript version of the display.xdiskusage is nice if you want to easily see where the space on your hard drive goes.

Install xdiskusage in Ubuntu

sudo apt-get install xdiskusage

If you want to open this application you need to use the following command

sudo xdiskusage

Once it opens you should see similar to the following screen

Sponsored Link

You may also like...

55 Responses

  1. Sureinlux says:

    Excellent excellent, just the right one for space conscious ppl like me. Great tutorial.

  2. nico says:

    hi,what do u mean by orphan package?thx..

  3. admin says:

    orphan package means broken packages and if you uninstall some packages some of dependencies might leftout if you want to remove all these packages use this tutorial.

  4. ikaruga says:

    If you use “aptitude” instead of “synaptic,” it *automatically* removes orphaned packages when you remove a package. The drawback is that it has a text gui, but it is very easy to use.

  5. Sak says:

    Edgy also includes “autoremove” as an extension of apt-get, so apt-get autoremove will remove any leftover packages that were dependencies if a package is uninstalled. So while aptitude removes dependencies as you remove an app, apt-get autoremove will get rid of anything that was left behind an uninstall performed by apt-get or Synaptic.

  6. Trix says:

    So what is the different between apt-get autoclean and apt-get autoremove?

  7. mocoloco says:

    For those worried about space, when you use apt or a front end to it (Synaptic, Add/Remove, Aptitude, etc) it keeps all the “install” files (.deb) it downloads in a cache, even after they’ve been installed. You can see them in /var/cache/apt/archives. Easiest way to manage this is in Synaptic, Preferences -> Files, you’ll see a button to delete the current cache, and options to choose what to do with these files in the future.

  8. Rebel says:

    Glad I came across this site. I was just about to install Ubuntu Mint 2.2 after trying out Xubuntu 7.04 Any opinions on Xubuntu? I am going to try it out on a 633Mhz Intel EMachine. Doorstop material but not for LINUX!!

  9. Have a look at FSlint also.
    It has functions for cleaning duplicate files,
    and a handy interface for removing uneeded packages.

  10. Jim says:

    Thanks, that was what I needed, forget to write stuff down sometimes. I am running Gutsy and doing pretty well. I had a little problem with a Brother printer driver, I knew the workaround, cause it happened in Feisty. What happens is when dpkg hangs, you can’t install some things. Synaptic, apt, etc.,no frontends will work, the solution is to use sudo gedit /var/lib/dpkg/status and edit out the file(s) that caused the problem and save. As far as I know this is the only way at times –force didn’t work.It took a lot to figure this out and it’s not widely known. It is definately a bug. It’s a really bad one if you don’t know how to fix it. Of course, I knew the half installed package was still there. I had just deleted the log entry so it wouldn’t hang. So, yeah, thanks. One more thing sudo apt-get clean will clear the cache and I think resets the registers.

  11. n00b says:

    XLNT guide but I have one question -> At the same time as Deborphan told me everything were gone, KleanSweep noticed a couple of thousand more orphanded files… how is that possible?

  12. It’s also possible to define a custom filter in Synaptic for orphaned packages, instead of installing GTKOrphan. Click Settings > Filters, click New, Deselect All, and check the box next to “Orphaned”. Give the new filter a name, and click OK.

  13. Nate says:

    btw, xubuntu hardy(not sure bout all others)

    sudo deborphan | xargs sudo apt-get -y remove -purge

    Should be
    sudo deborphan | xargs sudo apt-get -y remove –purge
    Or simply
    sudo deborphan | xargs sudo apt-get -y remove -p

    Just for those that are new to linux(I am fairly new, few months ago and I would have been confused as to why it didnt work)

  14. phytovor says:

    Also kdirstat is available for graphical representation of disk usage if you’re running KDE

  15. pauliboogey says:

    after sudo apt-get -f install I get this:

    Reading package lists… Done
    Building dependency tree… Done
    Correcting dependencies… Done
    The following packages will be REMOVED:
    gtkorphan
    0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
    1 not fully installed or removed.
    Need to get 0B of archives.
    After unpacking 336kB disk space will be freed.
    Do you want to continue [Y/n]?

    When I abort i habe GtkOrphan under Administration but it doesn’t run. At the same time the update manager gives me:
    Software index is broken

    It is impossible to install or remove any software. Please use the package manager “Synaptic” or run “sudo apt-get install -f” in a terminal to fix this issue at first.

    Any ideas? cheers

  16. MasterOfTheHat says:

    Guess I’m a little late to the party, but thanks for posting this. It’s def helpful for those us still digging into *nix!

  17. Andrew Z says:

    BleachBit is another tool to clean up unnecessary junk

  18. luisro says:

    wont accept password for sudo apt. what can i do?

  19. Matey says:

    Hello;

    Does anyone know how to delete large and useless files from ubuntu system via terminal screen.
    our web server runs out of space some times and is not running a GUI.

    I want to know if there are files which grow quickly (like log files) and so make a cron job so I can delete them before the server crashes (I mean our web site slows down to halt while the server is still running).

    Oh when I do a df -h I get /dev/sda1 is 100% full, how do I know which is sda1 and which folder is sda2 etc.?

    (so I can look in appropriate partition to clean it up)?

    Thanks very much. This is a valuable site!

  20. Tundro Walker says:

    Also look up “bleachbit” and “Fslint”. FSlint is a good dupe/unnecessary program finder, but not quite as good as Bleachbit. Bleachbit is sort of like MS Windows CCleaner, where it digs through your whole system to find unnecessary junk to delete. You can run it as normal user to clean out your home dir and such, and then as root to clean up root things. I’ve used it and it seems relatively safe. However, you should still be careful. You have to download bleachbit from the web (not in the repo’s yet) and install it. I think it comes as a .deb file, so installation is a snap.

  21. Amedee says:

    Google for hardlink.py
    This script hardlinks identical files. Useful when you have a lot of duplicate files on one partition. But use with care.

    Also interesting: put your /usr in a squashfs and mount it with unionfs. When you have installed all the software you needed, /usr doesn’t change much. Size reductions from 2 GiB to 800 MiB are not uncommon. Also interesting for netbooks with a solid state HD. In theory using squashfs slows down your system, but according to some benchmarks on netbooks they actually work a bit faster! Your Mileage May Vary…

  22. Amedee says:

    Another interesting tool: ncdu.
    Consider it the console (ncurses) version of xdiskusage

  23. W B Somp says:

    Thanks for the excellent write-up. Helped me clean up tons of files left behind after uninstalls. NOW I am feeling very glad leaving behind Windoze!

  24. Kris says:

    Thank you for this article! It helped me free up 100mb on my dad’s netbook.

  25. Duane says:

    Cool. This is great for ASUS eeepcs. I’ve cleaned up my 4GB partition 🙂

    I also cleaned all logs with:
    sudo find . -name *.gz -delete

    Oh and I blew away all thumbnails from mozilla with:
    find ~/.thumbnails -name *.png -delete

  26. Milciades says:

    Very good tutorial. Thank you. It has help me a lot! =)

  27. frederik says:

    I followed the instructions and read the comments.

    This does not work:
    =====================
    sudo deborphan | xargs sudo apt-get -y remove –purge
    E: Couldn’t find package –purge

    This does not work either:
    ==========================
    sudo deborphan | xargs sudo apt-get -y remove -p
    E: Command line option ‘p’ [from -p] is not known.

    Now what ? Come on guys, please take more care when you give instructions, for the non-experts like me, thanks
    (I’m running Ubuntu Jaunty)

  28. frederik says:

    this does not work:
    sudo deborphan | xargs sudo apt-get -y remove –purge
    E: Couldn’t find package –purge

    this does not work either:

    sudo deborphan | xargs sudo apt-get -y remove -p
    E: Command line option ‘p’ [from -p] is not known.

    help?

  29. george says:

    Just leave off the -purge and the -p Enter it as

    sudo deborphan | xargs sudo apt-get -y remove

    I did and it processed anyway and saved me several hundred megs

  30. GĂĽray says:

    Tharks for the article. I will try most of them with my new ubuntu installation.

Leave a Reply

Your email address will not be published. Required fields are marked *