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]

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.

a schematic of the relationships between the directories and subdirectories listed previously

[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):

  1. public_html
    http://www.unc.edu/~YourOnyen/
    ../../ up five levels; will display the index at this level
    1. transportation
      http://www.unc.edu/~YourOnyen/transportation/
      ../transportation/ up four levels; will display "index.htm"
      1. index. htm
      2. planes
        http://www.unc.edu/~YourOnyen/transportation/planes/
        planes/ up three levels; will display "index.htm"
        1. index.htm
        2. Boeing
          http://www.unc.edu/~YourOnyen/transportation/planes/Boeing
          planes/Boeing up three levels, then down within that level; will display "index.htm"
          1. index.htm
        3. Lear
          http://www.unc.edu/~YourOnyen/transportation/planes/Lear
          planes/Lear up three levels, then down within that level; will display "index.htm"
          1. index.htm
      3. trains
        http://www.unc.edu/~YourOnyen/transportation/trains/
        trains/ up three levels; will display "index.htm"
        1. index.htm
      4. cars
        http://www.unc.edu/~YourOnyen/transportation/cars/
        cars/ up three levels; will display "index.htm"
        1. index.htm
        2. Honda
          http://www.unc.edu/~YourOnyen/transportation/cars/Honda/
          ../../Honda/ up two levels; will display "index.htm"
          1. index.htm
          2. Accord
            http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Accord/
            ../../Honda/Accord up two levels, then down within that level; will display "index.htm"
            1. index.htm
          3. Civic
            http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Civic/
            ../../Honda/Civic up two levels, then down within that level; will display "index.htm"
            1. index.htm
          4. Odyssey
            http://www.unc.edu/~YourOnyen/transportation/cars/Honda/Odyssey/
            ../../Honda/Odyssey up two levels, then down within that level; will display "index.htm"
            1. index.htm
        3. Nissan
          http://www.unc.edu/~YourOnyen/transportation/cars/Nissan/
          ../../Nissan/ up two levels; will display "index.htm"
          1. index.htm
        4. Saturn
          http://www.unc.edu/~YourOnyen/transportation/cars/Saturn/
          ../../Saturn/ up two levels; will display "index.htm"
          1. index.htm
        5. Ford
          http://www.unc.edu/~YourOnyen/transportation/cars/Ford/
          ../../Ford/ up two levels; will display "index.htm"
          1. index.htm
          2. truck
            http://www.unc.edu/~YourOnyen/transportation/cars/Ford/truck/
            ../truck up one level
            1. index.htm looking up from here

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]


HTML - practice | theory | tags | links | PATHWAYS | HTML terms | 02.01 | next session