SESSION 6			THE UNIX FILE SYSTEM


1. Filenames:

All information used by the system, programs and data, is stored in FILES.
Each file has a name. It is safe to use the characters a-z, A-Z, 0-9, 
. (dot) and _ (underscore). Other characters may have special meaning to 
UNIX and are best avoided.

Examples of valid filenames are: barr , physics_ph251 , fortran.f , read_me

Spaces are not permitted in file names.

Files starting with a . (dot) are special in the sense that they are not 
revealed by the `ls' command. They are hidden. However,

			ls -a

lists all (hence the `a') files. You will see listed files such as `.login',
`.cshrc' which customise your environment (do not alter these unless and 
until you are UNIX-fluent) , dot (.) and double dot (..) files (see below).


2. Directories:

Files connected with the same application are usually grouped together 
into DIRECTORIES. Directories are named in exactly the same way as files. 
Directories contain files, but may also contain sub- (or child) directories. 
These in turn may also contain sub-directories and so-on, so creating a 
tree of directories.

The UNIX filesystem is organised into a hierarchy of directories. 
The highest level of directory of the system is called the ROOT directory. 
It is specifiedby the single character

			/

Type

			cd /

This changes directory to the root directory. List all the files in the root 
directory by typing `ls'. However, if you type

			ls -F

directories are distinguished from other files by having a / (slash) typed 
after them. [Files which may be executed have a * appended to their name.]
You will see directories such as  bin , etc , usr , dev . These are sub-
directories of the root directory.


3. A file is fully identified in the file system by giving its complete 
PATHNAME. This is the path through the hierarchy (down the branches of the 
inverted tree) to the file. For example, the pathname for this file might be

	/usr/fsb/phys/hcb1/ug/courses/fortran/unixses/unixfilsys6

The path from the root (/) directory is through the subdirectories usr, fsb,
phys, hcb1, ug, courses, fortran, unixses to the file named unixfilsys7.

Because UNIX is a multiuser system it is necessary to keep users' work 
separate. So each user has his/her own HOME directory. When you log on, the
system puts you in your home directory.

The command 

			cd				(change directory)

always returns you to your home directory from anywhere in the file system.
Type `cd' and then type

			pwd			(print working directory)

This should show something like

			/usr/fsb/phys/your_login_name

This is the full pathname of your home directory (the path down the hierarchy
from the root to your home directory).

If you cannot remember where you are in the filesystem, `pwd' will tell you 
where you are, i.e. your WORKING DIRECTORY.


4. Users may create as many subdirectories below their home directories as 
they wish but they cannot (do not have permission to) alter the hierarchy 
above or to the side of their home directories.

To create a subdirectory below your working directory, type

			mkdir  directory_name

To remove an EMPTY directory, type

			rmdir directory_name


5. Moving between directories:

Create three levels of subdirectory from your home directory. For example, 
type `pwd' to check where you are. If you are not in your home directory, 
type `cd' to return there. Create a subdirectory of your home directory 
called `subdir1' by typing

			mkdir subdir1

Move to this directory by typing 

			cd subdir1

Create a subdirectory of `subdir1' called `subdir2' by typing 

			mkdir subdir2

Return to your home directory by typing `cd'. To move directly from your 
home directory to the directory `subdir2' type

			cd subdir1/subdir2

Type `pwd' to confirm your location in the system.

To move to the parent directory of any subdirectory, type

			cd ..

This is `cd space double dot'. The double dot always means the parent 
directory to your working directory (i.e. one level up). Thus, we can move 
up through the hierarchy by repeatedly using the above command. Use it and 
`pwd' to move all the way up the root and confirm that you cannot move any 
further.

An abbreviation for your working directory is `.'
An abbreviation for the parent directory to your working directory is `..'
An abbreviation for your home directory is `~'. Hence  cd ~  is another way
of changing to your home directory.



6. Summary

	/		the root directory
	~		your home directory
	.		your working directory
	..		the parent directory of your working directory
	mkdir		creates a subdirectory of your working directory
	rmdir		removes an empty directory
	cd		change directory
	pwd		print working directory
	


7. Exercises

a) Create a directory in your home directory called `courses'.
b) Create two subdirectories of `courses' called `ph251' and `ph221'.
c) Create subdirectories of each of these called `homework' and `labwork'.
d) Return to your home directory.
e) Move to the directory `labwork' of `ph215' directly.
f) Move up one level at a time to the root directory, using `pwd' to confirm
where you are at each stage.
g) Move directly to the directory `homework' of `ph221'. 
h) Move directly to the directory `labwork' of `ph251' (hint: use `..' 
repeatedly to take you up the tree before specifying the pathname to come
back down it).


END OF SESSION 6					file: unixfilsys6
