Sunday, March 13, 2011

Freeing hard disk space in Ubuntu Linux

Here are some helpful disk cleanup tips that I came across during my quest to free up space on my tiny 4GB netbook hard drive.

1. apt-get

This command is what you use in Ubuntu to install and update the applications on your computer.  But apt-get can also be used to free up disk space:

sudo apt-get clean
Deletes package files that were downloaded when installing or updating software.

sudo apt-get autoclean
Like "clean", but only removes packages which are no longer in the Ubuntu repository or for which a newer version exists.

sudo apt-get autoremove
Removes dependencies that are no longer used by any applications.  For example, a spell checker library may have been installed along with OpenOffice.  However, when OpenOffice is uninstalled, the spell checker might not be.

2. du

This command won't itself free any space, but it can show you which files and directories are the biggest hogs (maybe there's a large video file buried somewhere that you don't know about).  The following command will recursively list all files and directories in the given directory and sort the list by file size.

du -a folder/path | sort -n

It's going to list every single file, so the list might get quite long.  It might be good to direct the output to a file and reverse the sort so the largest files appear at the top of the file:

du -a folder/path | sort -nr > disk-usage.txt

3. localepurge

If you can only speak one language like me, then check out localepurge.  It will remove all help files from your system that are in languages you don't understand.  It automatically runs every time you install any new software.

sudo apt-get install localepurge

As soon as it is installed, it will ask you for the languages you want to keep.  For example, I selected "en", which is the two letter code for "all variants of the English language" (American English, British English, etc).  I selected this instead of just "en_US" (American English) to err on the side of caution.  Note: Press the spacebar to select a language from the list and then press enter when you are done.

Then, run the program:

sudo localepurge

It will go through your hard drive and delete various files such as man pages.  It freed a good 53MB for me:

4. Language packs

You can also try removing language-related packages using the Synaptic Package Manager.  Search for "language" and remove all languages that you have no need for.  Sort by the left-most column so that the installed packages appear first in the list.  This freed even more space for me--about 200MB.

Do you have any tips for freeing up hard drive space?  Let me know!


PDF signature said...

Its really necessary to clean up the disk from time to time as it will improve the speed as well as efficiency.The tips you gave are really amazing.Nice blog.

patternpusher said...

You have #2 titled as "df". That's the disk free utility. It should be "du".

Michael Angstadt said...

Oops, thanks patternpusher.