next up previous contents
Next: Running a program Up: Files & Directories Previous: Directory Contents

How to view other Directories

UNIX has the notion of a current directory. This is the directory the user is currently using. To change the current directory we use the cdgif command.

Assuming the current directory is the same as above, we can change to the data directory by typing the following:

$ls -F
a          b          c          data/      junk/      programs/
$cd data
$ls  -F
g          h          i          personal/
$

There are three special directory names in UNIX. The current directory is just called '.', the next directory up the directory tree is called '..' and the user's home directory is called ' ~ '. Here are three examples:

$cd .
$ls -F
g          h          i          personal/
$cd  ..
$ls -F
a          b          c          data/      junk/      programs/
$cd ~
$ls -F
a          b          c          data/      junk/      programs/

To find out what our current directory is we can use the pwdgif command:

$pwd
/home/ugrads/unix_course

We can now see that our current directory is called 'unix_course'. It is a subdirectory of 'ugrads', which in turn is a subdirectory of 'home', which is a subdirectory of the root directory '/'.

To get to the directory home we could either use two steps:

$cd ..
$cd ..
$ls -F
ftp/     local/   test/    ugrads/
$

Alternatively we could use an absolute path name:

$cd /home
$ls -F
ftp/     local/   test/    ugrads/
$

A third option is to tell the shell to go to the next directory up and then up again in one step:

$cd ../..
$ls -F
ftp/     local/   test/    ugrads/
$

There are two types of path name being used here. The first method is relative to the current directory. This is a relative path name. The second method is relative to the root directory or absolute. This is a absolute path name.



Mark O. Stitson
Wed Sep 25 10:45:32 BST 1996