Learn by reading through in order

Paths and Directory Navigation — Absolute vs Relative

This article is part of the Linux Course, where you master practical Linux skills from scratch, from basic commands through to shell scripting.
Learn absolute vs relative paths, how to use the special symbols . .. ~ /, and how to read your location with pwd and ls -l — by moving around in a browser terminal.

Absolute and relative paths

A path is a string that describes the location of a file or directory.

One that starts from / is an absolute path (a complete route from the top of the file system), and one written from your current location is a relative path.

cd /tmp moves by absolute path; cd .. moves by relative path.

How a path is written and where it points
cd /tmp/tmp(absolute = from /)cd ..up to the parent(relative)cd ~/root, to home
An absolute path is traced from /; a relative path from your current location.
cd /tmp     # move by absolute path
pwd         # /tmp
cd ..       # up one level by relative path
pwd         # /
cd ~        # to home
pwd         # /root

① Move to /tmp by absolute path, and show your location with pwd to confirm.

② Then move up one directory with the relative .., and check your location with pwd.

③ Finally, return home and confirm with pwd that you're back at /root. (Run it correctly and an explanation will appear.)

Linux console
0 / 4 completed
Loading Linux Terminal...

Special symbols — / . .. ~

Inside a path, the following symbols have special meaning.

Combine them and you can move flexibly relative to your current location.

. refers to the directory you're in right now, and is used for things like a copy destination or an execution path.

When / appears in the middle of a path, as in /etc/hostname, it acts as a separator joining directories together.

SymbolMeaning
/Root (top level). At the start it means an absolute path; in the middle it's a separator
.The current directory
..The parent directory one level up
~The home directory (here, /root)
ls .                    # the current location = same as omitting it
cp /etc/hostname .      # copy to the current directory
./script.sh             # run from the current directory
mkdir -p a/b/c   # create a hierarchy for practice
cd a/b/c         # move deep by relative path
pwd              # ends with /a/b/c
cd ../..         # go up two levels
pwd              # ends with /a

① Create a three-level hierarchy with mkdir -p a/b/c for practice.

② Move to a/b/c by relative path, and confirm with pwd that it ends with /a/b/c.

③ Join two .. to go up two levels, and confirm with pwd that it ends with /a.

Linux console
0 / 4 completed
Loading Linux Terminal...

Read your location — pwd and ls -l

pwd shows the absolute path of your current location.

ls -l lists the items in that directory in detail, one per line, and passing it a path like ls -l / lets you check that location's contents without moving there.

Reading your location
pwdthe currentabsolute pathls -lcontents of thecurrent locationls -l /what's directlyunder root
pwd for your location, ls -l for that location's contents.
pwd          # current absolute path
ls -l        # detailed listing of the current location
ls -l /      # check directly under root without moving

① Show the absolute path of your current location with pwd.

② List the current directory's contents in detail with ls -l.

③ Use ls -l / to check what directories sit directly under root, without moving there.

Linux console
0 / 3 completed
Loading Linux Terminal...
QUIZ

Knowledge Check

Answer each question one by one.

Q1Which is the correct description of an absolute path?

Q2What does .. refer to in a path?

Q3What does pwd display when you run it?