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.
- Paths beginning with a
/
are specified starting at the root directory. - The symbol
~
is shorthand for your home directory. It is an absolute path. Try going anywhere in the file system and typecd ~
; it will take you straight home, just ascd
does by itself. - A path beginning with
~someUserName
specifies the home directory of the usersomeUserName
.
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
- Try typing
cd ..
thenpwd
a few times. What happens? - Type
cd
. Where do you go? - Type
cd /bin
(on a mac/usr/bin
) thenls cd*
You will see a file namedcd
that lives in that directory. - Type
ls c*
. What do you think the * does? - Try
ls *em*
. What do you see. What do the listed items all have in common?