4. Paths

The location of your home directory is specified by a path that looks something like this /home/morrison. This path is an example of an absolute path, because it specifies a location in the file system starting at the root directory.

All absolute paths start with a / or a ~. Here are the three kinds of absolute paths.

Absolute paths work exactly the same, no matter where you are in the file system.

Relative paths are relative to your cwd. Every directory contains an entry for its parent and itself. Make an empty directory named ghostTown and do an ls -a.

unix> python3
unix> mkdir ghostTown 
unix> cd ghostTown/
unix> ls -a
.  ..

If you type cd .., you are taken to the parent directory of your cwd; this path is relative to your cwd. Any path that is not absolute is relative. When you are navigating in your home directory, you are mostly using relative paths. Note that any relative path can also be represented as an absolute path.

Programming Exercises

  1. Try typing cd .. then pwd a few times. What happens?
  2. Type cd . Where do you go?
  3. Type cd /bin (on a mac /usr/bin) then ls cd* You will see a file named cd that lives in that directory.
  4. Type ls c*. What do you think the * does?
  5. Try ls *em*. What do you see. What do the listed items all have in common?