Cleaning up files

Cleaning up CSE home-directory files

If you have received a warning email from System Support, or have pro-actively identified that you are nearing your Disk Quota, then you will need to delete or alternatively compress some files to free up some space.

Identifying files

The first thing to do is identify which files are using the most space, this is achieved in one of two ways:
  • GUI: Applications Menu → System → Disk Usage Analyser (Also called baobab)
  • Terminal: du -ah ~ | sort -hr | less
(Other suggestions for helpful tools welcome.)

Core files

Core dump files are generated when you experience a system crash; they are:
  • usually named or contain the word core;
  • usually very large, in the order of 100s of MBs;
  • only useful if you wish to debug the crash event.
core file can be safely deleted. rm core

Temporary files

Many programs store files in a disk cache. You can safely delete most of these.
Here are some examples of directories that contain cache data: ~/.fonts.cache-1 ~/.java/deployment/cache ~/.adobe

Old Files

If you have work from previous sessions that you don't really want to delete ("just in case"), then just remember that if it's over a month old, it should be on the CSE Backups. You can check with Restoring Files for files marked as f.

If you have files that you want to only access occasionally, but no longer update, consider exporting them to a USB PenDrive or optical disk: then remove them from your account.

Not-so-important files

Some files/directories can be removed safely, and will be recreated when the source application runs: ~/.openoffice ~/.openoffice.org2 ~/.eclipse

Deleting files

This should be your first choice...
  • Within the Baobab app, you can select files and opt to Move to Trash.
  • Conform Menu → Applications → System → Administration → bleachbit (GUI).
    • bleachbitis a powerful and user-friendly cleanup tool with a self-explanatory GUI front-end.
  • Alternatively, in a terminal, you can use the rm command.
    • If you want to delete a directory and all files under it, you can use rm -r (-r is for recursive).

Files that won't delete...

Sooner or later everyone makes a slip and ends up giving a file a dumb name that seems to make it impossible to delete the file. Trying to rm it just returns the error message no such file or directory. But as you should know by now, in Unix there is always a way. There are two main cases:
The filename has hidden characters
Usually the hidden character is one or more spaces, sometimes it's a control character. You can amuse yourself by guessing the number of spaces and enclosing the filename in quotes, e.g. rm "foo " Or you can try to force a match on the filename by using the file-completion feature of your shell (ie. type in the first few characters of the filename and then hit the TAB key), or using the wildcard *.
The filename has shell metacharacters
The classic case is a filename starting with -. You can try referring to the file as ./-foo, or escape the metacharacter with a \, or use the '-' or '--' flag in the rm command (use man rm to see which is installed on your system), which forces rm to take whatever follows as the name of a file to be removed.
If none of these work then your best bet is to avoid trying to name the file yourself. Use rm -ri . to make Unix find the file for you, and with great care say 'y' to the file you want removed, and 'n' to all the others. A less dangerous method is to refer to the file by its inode number, which is its real name as far as Unix is concerned anyway. Use ls -i to find out the inode number, and then use find . -inum inode -ok rm '{}' \; The advantage of this method is that it also allows you to rename the file if you actually want to keep it, but have been unable to access it because of the funny characters. To rename the file, use find . -inum inode -ok mv '{}' new-file-name \; If you don't want the -ok safety check, use -exec instead.

Compressing files

There are a number of programs you can use to archive and compress your files.
In the UNIX environment, the most popular and distributed are: These programs have manual pages you should read if you intend to use them (just follow the links above). There are a plethora of compression utilities available in the Windows environment, the most common being WinZip and WinRar (though now Windows XP has built-in compression options in the right-click menu). These can be used to handle binhex-ed files (you may need to rename the file into something with ".bhx" suffix first). If you normally use a UNIX computer but need to decode a file in binhex (or other windows-based) format you may be able to use our Windows Terminal Servers to run the WinZip software. One of the main reasons that people at CSE need to compress files is that they have exceeded their quota on their UNIX account. To make this process easier, here are some instructions for compressing files and directories in your UNIX account:
  • To compress a single file, you can use any of the three methods mentioned above, e.g.
gzip myfile.c which will produce a compressed version called myfile.c.gz but taking up much less space. You can uncompress it with the command gunzip.
  • gzip only works on a single file, so how do you compress a whole directory structure? Say you have completed the CSE subject COMP1011 and you have a directory (conveniently called 'comp1011') full of files you no longer need but might want to look at later. How do you compress the whole lot?
You can use the program called tar to archive this whole directory, and its subdirectories and all the files in those directories, into a single file. This saves space by compacting the data together, but does not actually compress anything. In the example mentioned here you would use the command: tar cvf - comp1011 | gzip > comp1011.tar.gz Note that this will leave the comp1011 directory untouched and you will have to remove it yourself to save the space. Also note that we use gzip to compress your tar archive (This handy trick can save you a lot of disc space.)
Last edited by robertd 13/03/2017

Tags for this page:

cleanup, delete, disk, file, quota, space, compress