Cleaning up your Linux OS

A short blog with some commands that I often use myself whenever one of my Linux VMs is running out of space.

Where are those large files?

Step one in trying to solve an out of space problem is trying to figure out where my space meant. A useful command here is du. I use it with these switches:

du -hx -d 1 / |sort -h

This gives a sorted output in human readable format for all directories from the root with a depth of one, so it gives you an indication of which directories have grabbed your space. From there you can do the same command in the directory you want to examine closer. The -x excludes nsf shares etc which are linked to your VM, as I’m typically not interested in them when I’m out of space and it often takes a long time to calculate those. If you want to exclude certain directories from the calculation, you can add the –exclude=<name of directory> switch.

Delete old log files

So you found out that some log files grabbed all your space. How do you quickly throw away all the old log files? A combination of find, mtime and rm does the trick here. This command:

findĀ /path/to/files/*.log -mtime +5 -exec rm {} \; 

Finds all .log files that are older than 5 days and removes them.

My diskspace was eaten by IBM Installation manager

A less general Linux tip, but usefull when you work with a lot of IBM software. Installation Manager by default gives you the possibility to rollback changes, so if you upgraded to a newer version, you can still go back. Nice, but those files can take up a lot of space.

  • In Installation Manager, go to the File > Preferences option, then choose the “Files for Rollback” category.
  • Uncheck the “Save files for rollback” box to stop saving backup files in IMShared.
  • Click the “Delete Saved Files” button to remove the content which isn’t needed from the IMShared directory. The size of the saved files is the recovered file space.