Absolute vs. relative addressing
This exercise will help you get used to how UNIX nests files inside directories, in much the same way Windows nests files inside folders.
We'll use it to describe absolute and relative addressing.
Create a series of directories in your home directory to match the following description. Feel free to change the directory names, but keep the structure. Draw a picture of the resulting file system. Make sure you can navigate to every directory.
Make a directory in your home directory named transportation that contains three other directories
transportation [directory]
-
planes [subdirectory of
transportation]
- Boeing [subdirectory of planes]
- Lear [subdirectory of planes]
- trains [subdirectory of transportation]
-
cars [subdirectory of
transportation]
-
Honda [subdirectory of
cars]
- Accord [subdirectory of Honda]
- Civic [subdirectory of Honda]
- Odyssey [subdirectory of Honda]
- Nissan [subdirectory of cars]
- Saturn [subdirectory of cars]
-
Ford [subdirectory of
cars]
- truck [subdirectory of Ford]
-
Honda [subdirectory of
cars]
The following is one possible sequence of commands (other sequences are possible) to carry out this UNIX operation:
<cd ~> (this will put you in your home directory if you are not already there)
<mkdir transportation>
<mkdir transportation/
planes>
<cd transportation>
<mkdir cars>
<mkdir trains>
<cd planes>
<mkdir Boeing>
<mkdir Lear>
<cd ../cars>
(takes you up one level and then down into the cars directory)
<mkdir Honda>
<mkdir Nissan>
<mkdir Saturn>
<mkdir Ford>
<cd Honda>
<mkdir Accord>
<mkdir Civic>
<mkdir Odyssey>
<cd ../Ford>
<mkdir truck>
Your directory structure might look like the image below.

[top]
Now, assume this is a web site ...
and you have pages inside each directory and that each directory has an index page. Your web site structure might look like the following (UNIX file location, followed by absolute URL, followed by a URL relative the the lowest level in this structure, which is the Ford/truck directory):
-
public_html
http://www.unc.edu/~YourOnyen/
../../ up five levels; will display the index at this level- transportation
http://www.unc.edu/~YourOnyen/transportation/
../transportation/ up four levels; will display "index.htm"- index. htm
-
planes
http://www.unc.edu/~YourOnyen/transportation/planes/
planes/ up three levels; will display "index.htm"- index.htm
-
Boeing
http://www.unc.edu/~YourOnyen/transportation/planes/Boeing
planes/Boeing up three levels, then down within that level; will display "index.htm"- index.htm
-
Lear
http://www.unc.edu/~YourOnyen/transportation/planes/Lear
planes/Lear up three levels, then down within that level; will display "index.htm"- index.htm
-
trains
http://www.unc.edu/~YourOnyen/transportation/trains/
trains/ up three levels; will display "index.htm"- index.htm
-
cars
http://www.unc.edu/~YourOnyen/transportation/cars/
cars/ up three levels; will display "index.htm"- index.htm
-
Honda
http://www.unc.edu/~YourOnyen/transportation/cars/Honda/
../../Honda/ up two levels; will display "index.htm"- index.htm
-
Accord
http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Accord/
../../Honda/Accord up two levels, then down within that level; will display "index.htm"- index.htm
-
Civic
http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Civic/
../../Honda/Civic up two levels, then down within that level; will display "index.htm"- index.htm
-
Odyssey
http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Odyssey/
../../Honda/Odyssey up two levels, then down within that level; will display "index.htm"- index.htm
-
Nissan
http://www.unc.edu/~YourOnyen/transportation/cars/Nissan/
../../Nissan/ up two levels; will display "index.htm"- index.htm
-
Saturn
http://www.unc.edu/~YourOnyen/transportation/cars/Saturn/
../../Saturn/ up two levels; will display "index.htm"- index.htm
-
Ford
http://www.unc.edu/~YourOnyen/transportation/cars/Ford/
../../Ford/ up two levels; will display "index.htm"- index.htm
-
truck
http://www.unc.edu/~YourOnyen/transportation/cars/Ford/truck/
../truck up one level- index.htm looking up from here
- transportation
If you only want to point up to other locations in your file structure, use relative URLs and point to a location instead of an address. This would allow you to restructure a page without having to re-do all the hyperlinks.
You will want to use an absolute link to point to a location on another site, but a relative link to point to a location in your own file structure.
[top]