Disk Space Eaters in Linux

No matter how large a disk we buy for our system it eventually gets filled up. The most common disk fillers would be the unlimited amount of media we store these days, namely, videos, music, pics, games, ISOs. But sometimes a majority of the space is occupied by the crap you don't know, you don't care, you don't need and which is completely useless for you. I like to call these crappy files or folders as Disk Space Eaters  and in this article I will tell you how to find such space eaters and remove them safely.

I never actually noticed space eaters until recently a friend of mine came to me saying that he is unable to save anything in his root (/) partition. Even though the root partition was alloted around 8GB space and he has been running a lot of services on his computer for a long time but it was still hard to believe that so much space was somehow filled up. I started looking for the space eaters and found out that the culprits were logs and package archives. They both were consuming more that 2 GB of space. So, here are some of the major space eaters that could be occupying a major portion of your hard disk.

Log Files

These are simple text files, you can find them in /var/log folder. They don't seem to be a big threat but if you  run a lot of services that require logging or its been a long time since the system installation these files grow bigger and start consuming a lot of space. Logs are important but if you are a regular desktop user I don't think you really need or care for Logs. You can check the size of the logs using "du" command, here is an example.

[shredder12]$ du -sh <file or folder name>

If you want to know the size of every file in a directory use

[shredder12]$ du -h <foldername>

Now, there are two ways to get rid of them. First, would be to delete them and the other would be to tar and compress them, since they are just text files the compression will reduce their size effectively. You can delete a single file, single folder or multiples using the tar command. See the syntax below.

[shredder12]$ tar -cvzf compressed_logs.tar.gz logfile1 logfile2 alogfolder

This command will tar and compress logfile1, logfile2 and alogfolder into "compressed_logs.tar.gz".

P.S.- Deleting logs might not be a good idea until you know what you are really doing because some services need logs to work.

Package Archives

Whenever we install a package using apt-get or yum the package's installation file is stored in the disk. They are mostly stored in /var/cache/ folder. They are mostly useless, if you are use apt-get then you can remove them by running.

[shredder12]$ sudo apt-get autoclean

or you may use "clean" inplace of "autoclean". The difference is that clean removes all the packages and autoclean removes only those which can no longer be downloaded and are largely useless.

Thumbnails folder

If you are using Gnome and save a lot of media (videos or pics) then you would want to check out the size of the ~/.thumbnails folder(use the same "du" command mentioned above). This is where the video or picture thumbnails are stored. I am not sure about thunar of Xfce or Konqueror of KDE but you can easily find the thumbnails directory location for them too.

If its size is more than you would want it to have then you can just delete the directory and the next time you open a folder with media in it, they will be automatically generated (if you have a fast system if won't take any time). Delete them using the following command.

[shredder12]$ rm -r ~/.thumbnails

How to find other space eaters

In my opinion, the best way to find out other such files would be to find the files consuming most of the space and then see if they are of any use to you or not. You can do this by running the following command.

[shredder2]$ du  -cx  Downloads | sort -n

what this command does is, it gives the output of the size of folders in the Downloads folder and sort them so that you can see the folder consuming the maximum size.

If you are interested in looking the file consuming maximum size then modify the above command  a bit.

[shredder12]$ du -cx Downloads/* | sort -n

The output will be a sorted list (by size) of all the files in Downloads folder. Try it out yourself and you will understand.

In case you want the output of files or folders in MBs, GBs too then you may try the "-h" attribute with "du". It shows the size in human readable format but don't sort the output if you are using this option.

Some of the other disk space eaters are those installed programs which are no longer required. These are the commands for different package managers to see a list of packages installed.

[shredder12]$ dpkg -l

[shredder12]$ aptitude search '~i'

[shredder12]$ yum list installed

You might need to be root in order to run these commands. Look for the packages you don't need anymore and get rid of them (i mean uninstall, don't go on deleting everything manually).

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Use syntax $$latex$$ to insert LaTeX formulas.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.