cse taggi

Log in

Cleaning up files

Cleaning up Files

If you are (nearly) over your Disk Quota, then you will need to delete or compress some files. So, here are some tips.

Clues

The disk_guess program will give you some clues as to what takes up the most space.

How to compress files

There are a number of programs you can use to archive and compress your files. In the UNIX environment three popular and useful ones are gzip, tar, and compress. 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: 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. 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.)

How to delete files

The rm program (for remove) is used to delete files.

If you want to delete a directory and all files under it, you can use rm -r (-r is for recursive).

Core files

core files are an easy way to consume disk space. When a program crashes, it will often `dump core', creating a core file containing information about the state of the program when it crashed. core files are often very large (megabytes), but are also very useful when trying to work out what went wrong. If you don't intend to use them for this purpose, they can be safely deleted by using the rm command. rm core

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 our Full Backups. You can check with Restoring Files for files marked as f.

If you have a group of files that you want to look occasionally but no longer update, you might like to write them onto a CD and remove them from your account. This means that you can read the files when you like, but they will not be written repeatedly to monthly backup tapes.

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 ~/.mozilla/*/*/cache ~/.java/deployment/cache ~/.adobe

Not-so-important files

These directories are usually fairly large and safe to delete. You may lose some settings though for the related program. If you use that program regularly, you may not want to delete it. ~/.openoffice ~/.openoffice.org2 ~/.eclipse

Files that don't want to be removed

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.

Tags for this page:

cleanup delete disk file quota space compress