The K Desktop Environment

Next Previous Table of Contents

6. Cleaning Up

Finding out what is wrong is the first step. But KDirStat even supports you with the next step: Fixing the problem.

No, this section is not about ordering hard disks from your local computer hardware vendor. It is about cleaning up your hard disk - reclaiming lost disk space.

More often than not, your hard disk is perfectly sufficient. If only everybody would make good use of it. But typically nobody cares about hard disk space as long as there is plenty available. Or at least some. People don't clean up their home or working directories if they are not forced to. Forced to by the system administrator or by a 'no space left on device' message.

There are a lot of routine tasks you can perform in order to reclaim disk space. And KDirStat tries to help you perform the common ones. This is what this section is all about.

6.1 Predefined Cleanups

There are some predefined cleanup actions for common situations in a typical Unix working environment. And there are some escapes to more generic utilities like 'KFM' that let you do even more. And, of course, a plain vanilla shell escape. What could be more powerful than being able to invoke any Unix command in the working environment you are most used to - the Unix shell?

You can access the cleanup actions via the 'Clean up' menu. This will affect the object that is currently selected in the tree window.

Or you can access them via the tree window's context menu: Right-click on any object name and select any of the context menu's options.

Open in KFM

This will open the selected object in a KDE File Manager (KFM) window. If you selected a directory, you will see the directory's contents in that window. If you selected a plain file, KFM will try to open it according to its MIME types - i.e. it will start a postscript viewer for '.ps' files etc.

This cleanup action gives you most power without resorting to Unix command lines. You can do anything that KFM can do.

When you are finished, you might want to refresh your KDirStat tree display ('View' 'Refresh') to reflect your changes. This is not done automatically by default.

Open in Terminal

This will start a terminal emulation with the currently selected item's path as the current working directory. In effect, it will 'cd' to that path and then start 'kvt' (or whatever terminal program you configured).

If all else fails (or if it is just more efficient to type some Unix commands), this will give you all of the power your Unix operating system has to offer.

You might want to just close that shell window when you are finished in that directory. It is usually much more efficient to just start another one in another directory than typing numerous 'cd ..', 'cd ..', 'cd xy', 'cd yz' commands.

And if you changed something, you might want to refresh the KDirStat tree display.

Compress

This will compress an entire directory, i.e. make a '.tgz' file from it. A directory '/work/kilroy/anything' will become a file '/work/kilroy.anything.tgz' with this option; the original directory will be deleted after the compression.

I used to to that manually so many times I really wondered why nobody bothered to include this in any other program - not even in 'KFM'.

You can easily unpack this file with KFM's context menu. Or, better yet, you don't even need to unpack it if all you want is access one single file. Just click into it from KFM.

Please notice that any existing '.tgz' file of the same name will silently be overwritten by default.

KDirStat will automatically refresh the parent directory branch after performing this cleanup action.

make clean

This will 'cd' to the selected directory and perform 'make clean' there.

How many times did you FTP something from the internet, compile it, install it and then just forget about all the intermediate files in the build directory? All the '.o' files and executables that eat up a lot of disk space but are essentially unnecessary once the program is installed? You can easily fix this with 'make clean' there. But you don't even need a shell window for that. KDirStat can do that for you.

Please notice that by default this 'make clean' will rely on the local 'Makefile' there to handle recursing into subdirectories. I.e. 'make clean' will be called just once in the top level directory. This conforms to most internet projects' conventions (e.g. GNU, KDE, ...).

KDirStat will automatically refresh the directory branch after performing this cleanup action.

Delete Trash Files

This deletes files that are normally obsolete: Leftover object files ('*.o'), backup files created by some editors ('* ', '*.bak', '*.auto') or core dumps ('core'). Most file systems are cluttered up with those.

This command will descend a directory hierarchy and delete those files. They will really be deleted, not merely moved into the trash bin.

What exactly are 'trash' files is up to you to decide. You can and should customize this option before you use it.

Delete (to Trash Bin)

The most common cleanup action and the most dangerous one is deleting objects. KDirStat provides this operation in a play-safe manner: It moves objects into the KDE trash bin.

Yes, this doesn't really free up disk space right away. But you can perform this with some mouse clicks or with a simple keypress 'Ctrl-X' without lengthy confirmations.

I've seen so many confirmation dialogs pop up and being answered mechanically that I don't really trust them any more. If there are too many of them, people tend to click without thinking.

So here is KDirStat's approach: Just delete a file or a subtree into the trash bin. When you are finished working through your directory, open up the trash bin and look carefully what you marked for deletion. Think twice. And when you are really sure, empty the trash bin.

For performance sake, KDirStat assumes the entry you have requested to delete will be deleted and nothing goes wrong with that. It removes the object from the internal tree after starting the external delete command (really 'kfmclient move' with the trash bin as the target). If this doesn't work, you may need to manually refresh the tree display. But you will notice this soon when you receive a KFM error popup.

6.2 Customizing Cleanups

You can modify the predefined cleanup actions and you can create your own (up to ten). Select 'Settings...' from the 'File' menu and select the 'Cleanups' tab from the settings dialog.

Notice: You need to invoke 'Save Settings' from the 'File' menu later to make your changes permanent!

Select the cleanup action you want to customize from the list on the left side of the window. The values for this cleanup action will be displayed within the fields on the right side of the window. Any changes to those fields will not be lost when switching between cleanups.

Press the 'OK' button to apply your changes and close the settings dialog.

Press the 'Defaults' button to revert all settings to the default values as provided with the KDirStat distribution. You need to confirm this action.

Press the 'Apply' button to apply your changes and leave the settings dialog open. The settings dialog is not modal, i.e. you can work with the main window while it is open. With this option, you can experiment with your settings while still are changing them.

Press the 'Cancel' button to abandon your changes (since the last 'Apply' or 'OK' in this dialog) and close the settings dialog.

Enabled

This will enable or disable a cleanup action alltogether. You need to enable a cleanup action before you can modify it.

Title

This is a descriptive name for the cleanup action as displayed in the 'Clean up' or context menus. Use an ampersand ('&') to mark a character as menu accelerator.

Command line

This is the very heart of it. Enter the Unix command line you want executed here. Use '%p' as a placeholder for the full path of the selected object or '%n' as a placeholder for the file or directory name without path of that object.

The working directory of that command will always be the directory of the currently selected object - no need to manually 'cd' there.

Remember you can use several commands here - just about everything the Unix standard shell ('/bin/sh') understands. Use semicolons or '&&' to chain commands.

For example, the default 'Compress' cleanup uses a command line like that:


cd ..; tar czvf %n.tgz %n && rm -rf %n

Meaning:

'cd ..': Change directory one level up from where we started from.

';': There is more to follow.

'tar czvf %n.tgz %n': Create a compressed tar archive with the currently selected object's name (without path) plus '.tgz' from the currently selected object (always a directory in this case).

'&&': If this was successful, execute the next command.

'rm -rf %n': Recursively delete the currently selected object without asking dumb questions.

You see, even though there is no explicit confirmation for the final and dangerous step (deleting the original directory after creating the archive), this is fairly safe due to the Unix shell's capabilities.

Recurse into subdirectories

Most commands need to be invoked just once for the currently selected object. But sometimes it is much easier to invoke a command for any directory level.

For example, the 'Delete Trash Files' predefined cleanup would be much more complex without this option: A lengthy 'find ... -exec rm ...' would be required instead of a simple 'rm'. Otherwise, the wildcards in that command would be expanded at the top level directory only and most likely a most trash files would be left over.

Works for...

You can determine for what kind of objects a cleanup action makes sense. Menu entries will automatically be enabled or disabled accordingly.

Refresh policy

You can determine whether or not it is worth while or makes sense to rescan a directory subtree after performing a cleanup action:

No refresh

The cleanup action will not change anything. Or you don't care about it in order to save time and performance.

Refresh this entry

The cleanup action may change the currently selected object or anything below it.

Refresh this entry's parent

The cleanup action may change the currently selected object's parent or anything below it.

For example, the 'Compress' predefined cleanup not only changes the selected object (a directory) but also its parent: The parent will lose one child (the directory that will be deleted) and receive another one (the new '.tgz' archive). So really the parent needs to be refreshed.

Assume entry has been deleted

For the sake of performance, you can make KDirStat assume a cleanup action always deltes the currently selected object. This eliminates the need for a lengthy directory tree refresh. Just KDirStat's internally stored tree is modified.

But if this assumption is wrong maybe because an error occured KDirStat's tree may become out of sync with the data on the hard disk. In this case you need to manually refresh the tree or at least a branch of it.

Next Previous Table of Contents