Absolute vs Relative Paths: ., .., and ~ Explained

Absolute vs Relative Paths: ., .., and ~ Explained

Confused by How Paths Are Written?

"The guide says cd ../logs, but what is that ..?" "Where exactly is the ~ in ~/Documents?" As soon as you start learning commands, you run into these symbol-laden "addresses." They are called paths.

In this guide, Lina and Linny-senpai walk through the difference between absolute paths and relative paths, plus the meaning of three symbols: ., .., and ~. By the end, you'll be able to look at any path and know exactly which location it points to.

What You'll Learn

  • That a "path" is the address of a file or folder
  • The difference between absolute paths (starting from /) and relative paths (from where you are)
  • What . (here), .. (one level up), and ~ (home) mean
  • That the same location can be written two different ways
  • How to use pwd to check where you are when you get lost

1. What Is a Path, Anyway?

Conclusion: A path is the "address" of a file or folder—the route you follow through folders, written with / as the separator.

Lina: Linny-senpai, I keep seeing things like /home/lina/memo.txt in command guides, but I never know what they actually mean...
Linny-senpai: That's a "path." Think of it as an address that tells you where a file or folder lives.
Lina: An address?
Linny-senpai: Right. /home/lina/memo.txt means "the memo.txt inside the lina folder, inside the home folder." The / (slash) is the separator, and you go down one folder at a time.
Lina: I see! It's like a postal address narrowing down from country to city to street.

A path is the route to a file

In Linux, every file and folder lives in a single tree that starts at / (the root). A path describes which branches of that tree to follow to reach your target. The tree itself is covered in The Linux Directory Structure.

2. What Is an Absolute Path?

Conclusion: An absolute path always starts from / (the root). It points to the same place no matter where you are—like a full address written from the country down.

Lina: I heard there are different kinds of paths. Is that true?
Linny-senpai: Yes—there are two main kinds. Let's start with the "absolute path." Its key feature is that it always starts with /.
Lina: A slash at the very beginning.
Linny-senpai: Exactly. The / represents the top of the tree, the root directory. An absolute path writes out the full route from that top to your destination, leaving nothing out. So it points to the same place regardless of where you currently are.
Lina: So it's the same address no matter when I write it?
Linny-senpai: Right. The config file location /etc/hosts stays /etc/hosts whether you're in your home folder or anywhere else. It's like a complete postal address written from the country down.
cd /etc
pwd
/etc

Because /etc starts with /, you move there no matter where you currently are.

The giveaway is the leading /

  • Starts from / (the root)
  • Same result regardless of your current location
  • Best when you want to point to "exactly this place"—config files, scripts, and so on

3. What Is a Relative Path?

Conclusion: A relative path uses your current location as the starting point. It does not start with /, and where it points changes when your location changes.

Lina: What's the other kind called?
Linny-senpai: The "relative path." This one does not start with /. It writes the route starting from where you are right now.
Lina: Based on my current location...?
Linny-senpai: Right. If you're in /home/lina and type cd Documents, you move to /home/lina/Documents. It means "into Documents, as seen from here."
Lina: So if I run the same cd Documents somewhere else...?
Linny-senpai: The destination changes. If you're in /var, it looks for /var/Documents. That's why it's called "relative"—where it points shifts depending on where you stand.
pwd
/home/lina
cd Documents
pwd
/home/lina/Documents

A relative path's result depends on where you are

The same cd Documents lands you somewhere different if your current directory differs. When a command doesn't do what you expect, check your location first with pwd.

4. What Do ., .., and ~ Mean?

Conclusion: . means "here (current location)," .. means "one level up," and ~ means "your home directory."

Lina: Here's the big one—what are ., .., and ~, really? They've always been a mystery.
Linny-senpai: Great question. These are special symbols that shine when you write relative paths. Let's learn all three at once.
Lina: Please!
Linny-senpai: . (one dot) means "the place you're in right now." .. (two dots) means "one level up." And ~ (tilde) is a shortcut for "your home directory."
Symbol Name Meaning Example
. dot / current Where you are now ./script.sh (the script here)
.. dot-dot One level up cd .. (to the parent folder)
~ tilde Your home directory cd ~ (jump straight home)

Go up one level with ..

Lina: I feel like I see .. the most.
Linny-senpai: You use it a lot. From /home/lina/Documents, cd .. takes you up to /home/lina. Another cd .. takes you to /home.
pwd
/home/lina/Documents
cd ..
pwd
/home/lina

You can also combine them. cd ../../etc means "go up two levels, then into etc."

Jump home in one step with ~

Lina: When is ~ handy?
Linny-senpai: From anywhere, cd ~ takes you straight back to your home directory (like /home/lina). Think of it as a "go home" button for when you're lost deep in some folder. Running cd with no argument does the same thing.
cd ~
pwd
/home/lina

Writing ~/Documents points to "Documents inside your home," no matter where you currently are.

When do you use .?

You rarely type . on its own, but it shows up often when running scripts as ./script.sh. That means "the script.sh in the current folder." Without the ./, the shell searches its command path instead and may not find your file—so prefixing ./ is the standard way to run your own scripts.

5. Absolute or Relative—Which Should You Use?

Conclusion: Use an absolute path for certainty, and a relative path to move somewhere nearby quickly. The same location can often be written either way.

Lina: So how do I choose between absolute and relative paths?
Linny-senpai: Roughly: use an absolute path when you want to point somewhere "for sure," and a relative path when the target is "right nearby" and you want it short.
Lina: Can the same place be written both ways?
Linny-senpai: It can. If you're in /home/lina, both /home/lina/Documents (absolute) and Documents (relative) lead to the same /home/lina/Documents. Being shorter is the relative path's strength.

Here's the same move written two ways (current location is /home/lina):

cd /home/lina/Documents
cd Documents

Both end up moving you to the same /home/lina/Documents.

Rules of thumb

  • Absolute path: when you want to point to config files, scripts, or a far-off place "for certain"
  • Relative path: when you want to reach something "nearby"—right next door, one level up—quickly
  • When in doubt, an absolute path is safer (it doesn't depend on your current location)

6. What If You Get Lost?

Conclusion: Use pwd to check where you are. When a relative path misbehaves, suspect your current location first.

Lina: I ran cd with a relative path and got "no such directory"...
Linny-senpai: That's a classic beginner moment. A relative path is based on your current location, so if you're somewhere other than you thought, it fails. The magic word for that is pwd.
Lina: pwd?
Linny-senpai: It stands for "print working directory" and shows where you are. When you hit an error, check your location with pwd first, then rethink the route to your destination.
pwd
/var/log

If you're told "Documents doesn't exist," the pwd result lets you realize "oh, I'm in /var/log—let me use cd ~/Documents instead." Listing the current folder with ls to see what you can move into next also helps.

You can practice moving between paths right in your browser. Open the Penguin Gym Linux terminal and type cd and pwd over and over to feel how your location changes. Hands-on practice is the fastest way to learn.

Summary

  • A path is a file or folder's "address," written as a route separated by /
  • An absolute path starts from / (the root) and points to the same place regardless of your location
  • A relative path does not start with / and is based on your current directory
  • . is here, .. is one level up, and ~ is your home directory
  • When a relative path trips you up, check your location with pwd first

Next Reading