Larger hard drives should mean the end of disk space worries, but our appetite for bigger files has kept pace with all that increased capacity. Here are some effective ways to keep your Linux box from busting at the seams.
Do you remember the days when keeping a hard disk from getting full was essential to keep your machine running well? That was then, this is now, right? Well, not quite. The truth is, "The more you have, the more you need." Today, people are saving more on their drives, and that "more" consists of files that are far larger than what hard drives were once filled with. I see people filling up even terabyte drives faster than they can name the videos they just saved.
So... What do you do when that drive is full and your operating system is Linux? Do you have to do some special incantation or magical programming trick? Or do you just need a bit of common sense to help you through? Although common sense will be a great aid in this task, it also helps to know a few things about the operating system in general and how to use it properly. Let's take a look at some things you can do when your Linux box begins running out of space.
Note: This article is also available as a PDF download.
1: Use Computer Janitor (or its equivalent)
Ubuntu Linux has a handy tool called Computer Janitor. (You'll find it in the Ubuntu Software Center.) It will analyze your system and report which applications are no longer supported or no longer required. The tool is incredibly simple to use and will gain you some space, depending upon how many unsupported applications you have on your machine. This tool probably won't recover gigabytes of space, but you may recover a few hundred megabytes. And in the quest to gain as much space as you can find, every little bit helps.
2: Add an external drive
Linux really loves external drives. In modern incarnations, it doesn't matter if that drive is ext2/3/4, reiserfs, fat, vfat, NTFS, hfs... Linux can read it. Naturally, you're not going to move your applications to the external drive (although you could). But you can certainly use it as a data drive and move all of those precious family pictures, home movies, and MP3 collections to it.
3: Install the OS with /home on a separate drive
This makes sense on a number of levels. First, it moves all user data off the drive housing the OS. This also means when you reinstall the OS you don't have to worry about overwriting your user data. Of course, that's assuming you remember NOT to install the OS on the drive that contains all the data on your /home drive. (But if you forget and do that, this article won't help you anyway.)
4: Check your log files
Although this isn't nearly as common as an Exchange log getting out of hand, I have seen instances where a log file did not rotate and exceeded the normal size. The Linux operating system has a good log rotational tool, and usual logs shouldn't get the chance to grow overly large. But if that should happen, you can take advantage of the built-in logrotate tool to solve that issue. As a general rule, I have found this to be an issue only with non-system (or non-default system) software. Remember, all log files are usually housed in /var/log.
5: Clear your package manager cache
If you use a distribution that employs a package manager like apt, you can free up a good amount of space by clearing the cache. Apt retains the .deb packages it uses in /var/cache/apt/archives. You don't want to just delete those file, as that could have negative repercussions on the apt tool. Instead, use the built-in apt-cache tool to purge the cache and free up a good amount of space.
6: Clear application caches with Bleachbit
Another outstanding tool (also found in Synaptic) is Bleachbit. This tool clears only the various caches that applications use, but you will be surprised at how much space you can free up from clearing the cache of Adobe Reader, APT, Bash, Browsers, Evolution, Flash, GNOME, KDE, and many more applications. On a single run, without clearing the cache of all available applications, I was able to free up 485.9 MB. Not only will this give you more space, but some of those applications (the ones that tend to hold onto more cache than others) will begin running with more snap.
7: Write your own script
This is the approach that most hard-core Linux users prefer. Why bother with a fancy GUI when bash is all you really need? You can create a simple bash script to traverse the directory hierarchy and report which files are taking up the most space and delete them, if applicable. For example, this simple one line script:
find /home/jlwallen -size +1000000k
will print out the results of a find command, but only those files found that are larger than .95 Gb. Or you can find and delete duplicate files with a script like this:
find -type f | while IFS= read vo
echo `basename "$vo"`
doneCall that script duplicate.sh and then pipe its results through uniq, like so:
./duplicate.sh | uniq -d
This will print out all duplicate files you have on your drive, and you can then decide whether you want to delete them.
8: Remove applications
I know this sounds silly, but I bet if you went through the hierarchy of your menu you would find a good number of applications you simply do not use. Why keep them on there if you're not going to use them? Delete those bad boys and recover some space. This especially holds true if you like to install numerous applications just to test the waters. The best approach is to use your GUI package manager so you can simply scroll through what is installed and remove away.
9: Empty your Trash
In some instances (and distributions), Delete works similarly to how it works in Windows — instead of actually deleting the file, the file goes to the Trash. I have seen cases where the Trash was very full, and the act of emptying that directory freed up quite a bit of space. To clear it, simply right-click on the Trash icon and select Empty Trash.
Although this should be used only as a last-ditch effort, a clean installation certainly does restore that factory fresh smell, as well as giving you the chance to migrate to the latest, greatest version without the bad taste of doing an upgrade installation. Here's the kicker: If you have a TON of files in your ~/ directory, when you copy those back, you will wind up with the same tonnage on your newly installed system. Take this opportunity to either move those files to a new location or just weed out that huge collection of wallpapers you have from the '90s and the redundant backups of all your movies and MP3s.