Mastering Absolute and Relative Paths in Linux
Learn to navigate the Linux file system using absolute and relative paths. Master shortcuts like .. and ~ to speed up your terminal workflow today.
Previously in this course, we covered Navigating the File System: A Linux Command Line Guide, where you learned how to use pwd and cd to orient yourself within the Linux hierarchy. Now, we'll level up your navigation skills by mastering file paths, the precise language we use to tell the shell exactly where a file or directory lives.
Understanding Absolute Paths
An absolute path defines the location of a file or directory starting from the root of the file system, denoted by a forward slash (/). Because it starts from the absolute top of the tree, an absolute path is always the same, regardless of your current working directory.
Think of an absolute path like a global GPS coordinate. Whether you are in your home folder or deep inside a system directory, /var/log/syslog will always point to the same file.
Example:
If you want to move to the etc directory, which contains configuration files, you use:
cd /etc
No matter where you are currently, running that command takes you directly to the system-wide configuration folder.
Navigating with Relative Paths
A relative path defines the location of a file or directory based on your current working directory. Instead of starting from the root, you describe the route from where you are standing right now.
If your current directory is /home/user and you want to enter the documents folder inside it, you don't need to type the full path. You simply type:
cd documents
The shell understands this as "look in the current directory for a folder named documents."
Essential Shortcuts for Faster Navigation
To become proficient in the shell, you must memorize these three critical shortcuts. They save you from typing long, repetitive strings.
| Shortcut | Meaning | Use Case |
|---|---|---|
. | Current directory | Specifying a file in the folder you are in. |
.. | Parent directory | Moving one level up in the hierarchy. |
~ | User home directory | Jumping straight to your personal folder. |
Using the .. Shortcut
The .. (dot-dot) is perhaps the most used shortcut in Linux. It represents the directory "above" your current one. If you are in /home/user/projects and need to go to /home/user, simply run:
cd ..
Using the ~ Shortcut
The tilde (~) is a shorthand for your home directory (e.g., /home/username). It’s a massive time-saver. Instead of typing cd /home/student, you can simply run:
cd ~
Worked Example: Putting It Together
Let's imagine our project structure. We have a home directory, a web-server folder, and a logs sub-folder.
- Start in your home directory:
cd ~ - Move into the project directory:
cd web-server - Move into the logs sub-folder:
cd logs - Now, move back to the
web-serverfolder (the parent):cd .. - Finally, jump back to your home directory from anywhere:
cd ~
Hands-on Exercise
Open your terminal and follow these steps to practice path navigation:
- Use
pwdto confirm you are in your home directory. - Create a nested directory structure:
mkdir -p test/subdir/deeper. - Move into the
deeperdirectory using a relative path:cd test/subdir/deeper. - Use
cd ../..to move two levels up. - Use
pwdto confirm you are now back in thetestdirectory.
Common Pitfalls
- Forgetting the root slash: If you type
cd etcinstead ofcd /etc, the shell will look for anetcfolder inside your current directory. It will likely return a "No such file or directory" error. - Case Sensitivity: Linux is case-sensitive.
cd Documentsis not the same ascd documents. Always check your spelling and casing. - Leading spaces: Accidentally typing a space before a path can cause the shell to misinterpret your command.
FAQ
Q: How do I know if I should use an absolute or relative path? A: Use absolute paths in scripts or cron jobs where the location must be guaranteed. Use relative paths for manual, daily navigation because they are faster to type.
Q: Can I use ~ in a path?
A: Yes. cd ~/web-server/logs will take you to that specific path regardless of your current location.
Recap
You've learned that absolute paths are fixed, global addresses starting with /, while relative paths are "directions" from your current spot. By leveraging .. to move up and ~ to jump home, you've significantly reduced the keystrokes required to manage your environment.
Up next: Listing and Inspecting Files
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom Email & File Storage System on Cloudflare (Google Workspace Alternative)
Your own private email + file storage suite on your domain — unlimited mailboxes, no per-seat fees. A self-owned Google Workspace alternative for a flat ~$5/month.

