Pathnames locate a file (or directory, or any other object) in the UNIX filesystem. As you read this article, refer to Figure 1.4. It's a diagram of a (very) small part of a UNIX filesystem.
Whenever you are using UNIX, you have a current directory. By
default, UNIX looks for any files or directories that you mention
within the current directory. That is, if you don't give an absolute
pathname (starting from the root, / ), UNIX tries to look up files
relative to the current directory. When you first log in, your
current directory is your
cd /usr/bin). You can find out your
current directory by giving the pwd ("print working directory") command.
If your current directory is /home/mike, and you give the command cat textfile, you are asking UNIX to locate the file textfile within the directory /home/mike. This is equivalent to the absolute path /home/mike/textfile. If you give the command cat notes/textfile, you are asking UNIX to locate the file textfile within the directory notes, within the current directory /home/mike.
A number of abbreviations help you to form relative pathnames more
conveniently. You can use the abbreviation
. (dot) to refer to
the current working directory. You can use
.. (dot dot) to
refer to the parent of the current working directory. For example, if
your current directory is /home/mike, ./textfile is the
same as textfile, which is the same as /home/mike/textfile.
The relative path ../gina/textfile is the same as
.. moves up one level from
/home/mike (to /home), and then searches for the directory
gina and the file textfile.
In the C shell, ksh and bash, you can use the
~ (tilde) to refer
to your home directory.
name refers to the home directory of the user name.
Here's a summary of the rules that UNIX uses to interpret paths:
The C shell, ksh and bash turn it into an absolute pathname
starting at your home directory (
~), or at the home directory of the
user name (
The pathname is relative to the current directory. Two relative special cases use entries that are in every UNIX directory:
Article 18.2 explains where
.. come from.
..may appear at any point within a path. They mean "the current directory at this point in the path" and "the parent of the current directory at this point in the path." You commonly see paths starting with
../../(or more) to refer to the grandparent or great-grandparent of the current directory. However, they can appear at other places in a pathname as well. For example, /usr/ucb/./bin is the same as /usr/ucb/bin; and /usr/ucb/bin/../lib is the same as /usr/ucb/lib. Placing
..in the middle of a path may be helpful in building paths within shell scripts, but I have never seen them used in any other useful way.