Department of Computing Imperial College
Managing your file space

Imagine your file space as a filing cabinet with your files as records in the cabinet. If you randomly throw records into a filing cabinet the system becomes unmanageable, you cannot find things quickly, you do not know what you should keep, or even which records refer to each other. The answer is to use folders, grouping related information in one place, keeping it seperate from other records.


The equivalent to a folder in your file system is the directory. Directories allow you to separate files into a sensible structure. It is a good idea to start a new directory for each project that you start. For instance, a first year might want to setup their files structure thus:
	~/		(Your home directory)
	~/bin		(Binaries - application programs)
	~/man		(Manual pages for applications)
	~/lab		(Lab coursework)
	~/lab/ex1 	(Lab exercise one)
	~/lab/ex2 	(Lab exercise two)

Listing the Contents of a Directory

To list the contents of a directory, use the ls command. This command can take several flags (options which modify the output of the command), the more useful of which are:

ls -a
List all files - including hidden files beginning with a "." (i.e. .mail)
ls -l
List files in a long format, including file access privilege information.

ls -al
List all files, including hidden files, in a long format.

Directory Naming

There are essentially three ways of naming a directory:


Any path specified from the root directory / is absolute. For example:
/vol/bitbucket 	(shared file space)
/usr/bin/X11	(X11 specific binaries)	
/homes/abc96	(home directory of user abc96)

Relative to your current working directory

Your current working directory can be found by using the pwd command. Directories can be specified relative to this. For example:
bin	(The directory bin from with the current directory)
../	(The parent directory of the current directory)
../../	(The parent, of the parent, of the current directory)

Relative to a home directory

Directories can be specified relative to your (or some other users) home directory. For example:
~/		(your home directory)
~/bin		(the bin directory, in your home directory) 
~abc96/bin	(the bin directory, in abc96's home directory)
~/..		(the parent directory, of your home directory)

Making a Directory

To create a directory use the mkdir command. For example, to create a directory called bin in your home directory type:
	mkdir ~/bin

Changing Current Directory

To change your current directory, use the chdir or cd command. For example, to change directory to ~/bin, type:
	chdir ~/bin
	cd ~/bin

Removing a Directory

To delete a directory (you must own the directory), use the rmdir command. The directory must first be completely empty of all files (including hidden files). Use the rm command to delete files. Then use the rmdir command to remove the empty directory. For example, the following command will remove a directory called bin in your home directory:
		rmdir ~/bin

File Utilities

Several file utilities are provided to help with file management:
List the contents of directories.
Copy files and directories.
Move or rename files or directories.
Remove (unlink) files or directories.
Make hard or symbolic links to files.
Display the pathname of the current working directory.
Change current working Directory.
Make a Directory
Concatenate and Display files.
Browse or page through a text file.
Create archives, and add or extract files.
Compress or expand files, display expanded contents.
Change the access permissions of files.
Display a user's disk quota and usage.
Report free disk space on file systems.
Display the amount of disk space a user is using, per directory or file.
Find files by name, or by other characteristics.
Determine the type of a file by its contents.

Compressing Files

Any file that you do not use on a regular basis, can be compressed to save space:

gzip filename

and to 'uncompress':

gunzip filename

Important files in your account / Disk quota

© CSG / 1999 / / Top of page