DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Working with files and directories

Navigating symbolic links

Because the system uses symbolic links extensively, you may encounter problems in identifying your current working directory. For example, suppose you create a symbolic link to a directory, then change directory using the new link, as follows:

   $ ln -s /u/workgrp/tasks/projects mydata
   $ pwd
   /u/people/mike
   $ cd mydata
   $ pwd
   /u/people/mike/mydata
   $
In this example, you create a symbolic link called mydata, pointing to /u/workgrp/tasks/projects. However, if you change directory via the link mydata, you actually see yourself as being in /u/people/mike/mydata. This is the logical present working directory; that is, the path the user traversed to reach the directory. The directory also has a physical path, that is, the actual pathname of the current directory, relative to the top of the filesystem.

Now you are in /u/workgrp/tasks/projects. Suppose you create another symbolic link and change directory into it:

   $ ln -s /u/people people
   $ pwd
   /u/people/mike/mydata
   $ cd people
   $ pwd
   /u/people/mike/mydata/people
   $
When you change directory into people, you are following a link to /u/people. This is higher in the directory tree than your original starting point, but because you are traversing another symbolic link, your logical present working directory is another level down the tree.

If you then type cd .. (to go up a directory), where you end up depends on your shell. If you are running the Korn shell, the cd .. command goes up a level in your logical directory path: /u/people/mike/mydata becomes your present working directory. If you are running any other shell, the cd .. command goes up a level in your physical directory path: /u becomes the present working directory.

Despite the apparent complexity, it is possible to determine your physical working directory in a directory tree populated with symbolic links. There are two techniques, for Korn shell users and for others:


Korn shell users
Use the command pwd -P to identify your absolute current working directory. (The command pwd is built into the Korn shell. It normally returns the logical present working directory; the -P option makes pwd return the physical path to the current directory.

others
Use the command pwd(C). The non-Korn shells do not include a built-in pwd command. The external pwd command returns the physical path to the current directory by default.
In general, directory traversal commands built into the Korn shell accept two options, -P and -L. -P makes the command refer to the physical working directory, while -L makes the command refer to the logical working directory (that is, to the path taken through any symbolic links).

The equivalent commands, in any other shell, always apply to the physical working directory.


Next topic: Mounting a filesystem
Previous topic: Creating a link to a directory

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003