[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Free your space

Sometimes you can find yourself in a situation where you are suddenly faced with a message telling you that there’s no more free space on your system. There might be a few things you can do to free some of it.

/tmp directory

The first reason can be a /tmp directory which doesn’t get cleaned automatically. I create my own temporary files in my home directory so I can safely delete the contents of /tmp every time I shut down the system. You don’t have to do it manually, though.

The following command should be placed in /etc/rc.d/rc.local_shutdown.

/etc/rc.d/rc.local_shutdown.append
/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -exec /bin/rm -rf {} +;

This will delete ALL the files in the /tmp directory every time the system shuts down, so be careful what you put there!

The rc.local_shutdown file can also be useful in other ways. If you need to perform any other tasks on shutdown, you can put them here. As this file doesn’t exist on the default installation of Slackware, you need to create it first and make it executable:

root@darkstar# touch /etc/rc.d/rc.local_shutdown
root@darkstar# chmod +x /etc/rc.d/rc.local_shutdown
Remember to test your commands well before you include them in the shutdown file.

Alternatively, if you have enough RAM, you may mount the /tmp in tmpfs by adding the following to /etc/fstab.

/etc/fstab.append
tmpfs	/tmp		tmpfs	size=4G,nodev,nosuid	0	0

You can restrict the size of /tmp (max. 4GB in the example above) to avoid running out of memory.

There is also a more prudent way of cleaning up your tmp directory; this method consists of allowing the temporary files to exist for more than the amount of time between startup and shutdown. The following script selects files which haven't been touched for a certain amount of time and doesn't remove sockets for X. One could decide to run this script using cron on a regular basis.

cleanstale.sh
#!/bin/sh
# Cleanup /tmp however, do not remove sockets for X
 
# No lost+found with reiserfs
find /tmp/lost+found -exec /bin/touch {} \;
find /tmp -type s -exec /bin/touch {} \;
find /tmp -type d -empty -mtime +37 -exec /bin/rmdir {} \;
find /tmp -type f -mtime +37 -exec rm -rf {} \;
Again, please test scripts very carefully before deploying them on your system. As always: your mileage may vary.

sbopkg

root@darkstar# sbopkg -o
[ Checking for obsolete sources ]
This may take a few moments. Press <ESC> to abort.
100%[====================================================]
It appears there are no obsolete sources in /var/cache/sbopkg.

If you do not need the sources of packages installed via sbopkg, you may also want to clean the whole sbopkg cache. You can do it in sbopkg’s utility menu.

Finding files/directories taking up most space

It’s also good practice to find directories/files that take up most space. The following command will display 20 largest files/directories in a specified place (in this example Fred's home directory):

find_largest.sh
du -a /home/fred/ | sort -n -r | head -n 20

You can go through the list and decide whether you want to delete any of them.

A quicker approach might be to use ncdu, du's ncurses frontend. Not only does it display directories in your chosen order (ascending/descending, by size/name), but also lets you interactively browse (and be careful: delete) them.

To make sure you don’t delete something by accident, you can run the program in the read-only mode calling it with the -r flag.

Apart from ordering the files/directories by size or name, there are also a number of interesting display options like showing percentage or graph, showing/hiding hidden or excluded files and directories (you can exclude certain directories or files if you want.)

Although it is not part of the stock Slackware, it can be easily installed from SlackBuilds.org (it does not have any additional dependencies.)

Remove unnecessary programs

Another way of freeing some space is by uninstalling the apps that you no longer need. If you don’t know what you are doing, it is NOT recommended to uninstall anything from the Slackware’s default installation. You might break some parts of the system . A safer approach would be to uninstall some 3rd party applications. Long time ago you may have installed some applications from SlackBuilds that you no longer use. You can remove 3rd party programs using the following command:

root@darkstar# slackpkg clean-system

This will list all 3rd party packages and let you select the ones you want to remove. In order for an application to be included in slackpkg list it must have been built and installed the Slackware way, ie. by using a SlackBuild. Otherwise, it will not be part of the Slackware package management system.

If there's no SlackBuild for a program you want to install, try to create one or use the excellent src2pkg tool.

Disk Cleanup Utilities

Here are a list of disk cleanup utilities you might find useful to remove unnecessary or temporary files from your system.

  • Sweeper - A KDE disk cleanup application.
  • BleachBit - BleachBit quickly frees disk space and tirelessly guards your privacy. Free cache, delete cookies, clear Internet history, shred temporary files, delete logs, and discard junk you didn't know was there. A Slackbuild is available at SlackBuilds.org.

Sources

  • Originally written by sycamorex
  • Based on sycamorex's blog article here
  • Additional inputs by Harishankar (Disk Cleanup Utilities section)
  • Contrbutions by cpt (cleanup script), original script has been copied from a mail-list, cpt does explicitly not claim to be the original author of this script.

 howtos:general_admin:free_your_space ()