next up previous
Next: Internal and External Commands Up: The Tree Structure of Previous: The Tree Structure of

Current Directory, Absolute and Relative Pathname

Pathnames locate files in the UNIX filesystem. By default, UNIX looks for files or directories starting from the current directory. For example, if the current directory is /u/youruserid/cs241 then the UNIX command

a) cd a1

will switch into /u/youruserid/cs241/a1, if such a directory exists. Otherwise it will print an error message. If /u/youruserid/cs241 is the current directory then typing

b) more a1/q1.txt

you ask UNIX to locate the file q1.txt within the directory /u/youruserid/cs241/a1.
You can also type:

c) more /u/youruserid/cs241/a1/q1.txt

to view the same file.

Cases a) and b) use relative pathnames, case c) an absolute pathname.

Several abbreviations simplifying the work with pathnames exist:

. refers to the current directory
.. refers to the parent directory

For example, if /u/myuserid/cs241/a1 is the working directory and q1.txt is the file in a1 directory, then

more q1.txt

has the same effect as

more ./q1.txt

If the working directory is the same as above but you want to check the file q0.txt in directory a0 without changing the current directory, type

more ../a0/q0.txt .

In C shell, $\tilde{} $ is a shortcut to the home directory. For example, $\tilde{} $/cs241/lab2 is equivalent to the absolute pathname /u/myuserid/cs241/lab2. $\tilde{} $username switches to the home directory corresponding to username.

It this sense, UNIX allows practically anything and it the user's responsibility to set up permissions on his/her files in a way that the above features cannot be misused.

In summary,

As we will see shortly, it is very important to understand the difference between absolute and relative pathname.


next up previous
Next: Internal and External Commands Up: The Tree Structure of Previous: The Tree Structure of
Instructional Support Group 2008-08-05