DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Directory and file management

Relative pathnames

A relative pathname gives directions that start in your current working directory and lead you up or down through a series of directories to a particular file or directory. By moving down from your current directory, you can access files and directories you own.

For example, suppose you are in the directory starship in the sample system and starship contains directories named draft, letters, and bin and a file named mbox. The relative pathname to any of these is simply its name, such as draft or mbox. ``Relative pathname of the draft directory'' traces the relative path from starship to draft.

Relative pathname of the draft directory

The draft directory belonging to starship contains the files outline and table. The relative pathname from starship to the file outline is draft/outline.

``Relative pathname from starship to outline'' traces this relative path. Notice that the slash in this pathname separates the directory named draft from the file named outline. Here, the slash is a delimiter showing that outline is subordinate to draft; that is, outline is a child of its parent, draft.

Relative pathname from starship to outline

So far, the discussion of relative pathnames has covered how to specify names of files and directories that belong to, or are children of, the current directory. You can move down the system hierarchy level by level until you reach your destination. You can also, however, ascend the levels in the system structure or ascend and subsequently descend into other files and directories.

By moving up from your current directory, you pass through layers of parent directories to the grandparent of all system directories, root. From there you can move anywhere in the file system.

The relative pathname is just one of the mechanisms built into the file system to alleviate the need to use full pathnames. By convention, the path-prefix ``..'' refers to the parent-directory (that is, the directory containing the current-directory), and the path-prefix ``.'' refers to the current-directory.

A relative pathname begins with one of the following: a directory or file name; a ``.'' (pronounced dot), which is a shorthand notation for your current directory; or a ``..'' (pronounced dot dot), which is a shorthand notation for the directory immediately above your current directory in the file system hierarchy. The directory represented by ``..'' (dot dot) is called the parent directory of ``.'' (your current directory).

To ascend to the parent of your current directory, you can use the ``..'' notation. This means that if you are in the directory named ``draft'' in the sample file system, ``..'' is the pathname to ``starship'', and ''../..'' is the pathname to ``starship'''s parent directory, ``home''.

From ``draft'', you can also trace a path to the file ``sanders'' by using the pathname ``../letters/sanders''. The ``..'' brings you up to ``starship''. Then the names ``letters'' and ``sanders'' take you down through the ``letters'' directory to the ``sanders'' file.

Keep in mind that you can always use a full pathname in place of a relative one.

``Example pathnames'' shows some examples of full and relative pathnames.

Example pathnames

Path Name Meaning
 / full pathname of the root directory
 /usr/bin full pathname of the bin directory that belongs to the usr directory that belongs to root (contains most executable programs and utilities)
 /home/starship/bin/tools full pathname of the tools directory belonging to the bin directory that belongs to the starship directory belonging to home that belongs to root
 bin/tools relative pathname to the file or directory tools in the directory bin.
If the current directory is /, then the UNIX system searches for /usr/bin/tools. However, if the current directory is starship, then the system searches the full path /home/starship/bin/tools.
 tools relative pathname of a file or directory tools in the current directory.

Moving files to the directory ``.'' moves them into the current-directory. In addition, files can be linked across directories. Linking a file to the current-directory obviates the need to supply a path-prefix when accessing the file. When created, a process has one current-directory and one root-directory associated with it, which can differ for other processes. See ``Process management'' for more detail on processes.


Next topic: Symbolic links
Previous topic: Full pathname of the /home/starship directory

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004