Bash ‘cd’ Command: Master Terminal Navigation Now It’s time to stop feeling lost. Let’s learn to ‘Change Directory’ and move with confidence.
👋 Hey everyone,
Over the last two days, we’ve laid the foundation for our entire command-line journey. We’re on Day 6 of the “1-Month Bash Mastery Plan,” and we’re about to complete the most important “triad” of skills you will ever learn.
pwd(Print Working Directory): This was our anchor. It answered the question, “Where am I?”ls -lah(List Files): This was our light switch. It answered the question, “What’s in here with me?”
And now, today, we learn the third and final piece: cd (Change Directory). This is our movement.
pwd tells you you’re in a room. ls shows you the other doors in that room. cd is the command that lets you walk through those doors.
For the longest time, I was stuck. I could pwd and ls, but I couldn’t move effectively. I felt like I was standing in the hallway of a giant mansion, able to see the “Kitchen” door and the “Library” door, but I had no idea how to open them. I was a spectator in my own file system.
Today, we’re grabbing the keys. We’re not just going to learn cd [directory]. We’re going to learn the shortcuts that separate the beginners from the pros. We’re going to learn how to teleport home, how to jump up a directory, and the one magic command that acts as a “back button” for your entire terminal.
My Goal This Week 🎯
My goal for this post is to eliminate that “I’m lost and I don’t know how to get back” feeling forever. We will do this by mastering the cd command in its entirety.
By the end of this, you will have a rock-solid mental model for:
- Absolute vs. Relative Paths: The single most important concept for navigation.
- The “Big 3” Shortcuts:
cd ~(Home),cd ..(Up), andcd -(Back).
These three shortcuts, combined with a clear understanding of paths, are the entire foundation for moving around your system with speed and confidence.
The Process & The Code 👨💻
cd stands for Change Directory. Its one and only job is to change your “working directory”—the place where pwd says you are.
The real lesson here isn’t the command itself; it’s the argument you give it. There are two, and only two, types of paths you can give to cd (or any command, really).
1. The Two Path Types: The Core Lesson
This is it. This is the whole enchilada. Every “path” in Linux is one of these two things.
Absolute Paths (The Full Address) An absolute path is a “full” address. It always starts with a forward slash (
/), which represents the “Root” of the entire file system. It doesn’t matter where you are; an absolute path always leads to the exact same place.It’s like giving someone a full GPS coordinate or a complete mailing address:
1600 Pennsylvania Avenue NW, Washington, DC 20500In Linux, that looks like this:
# No matter where I am, this will take me to my "Projects" folder cd /home/murat/Projects # This will take me to the system's main log folder cd /var/logRelative Paths (The Local Directions) A relative path is a path relative to your current location (what
pwdshows). It never starts with a/. It’s a set of local directions.It’s like telling someone, “From here, go to the “Kitchen” door down the hall.” That only works if you’re in the right hall.
Let’s say
pwdshows/home/murat. I runlsand seeProjects.# 'pwd' shows /home/murat lsOutput:
Desktop Documents Downloads Projects ...# I can use a relative path to "move into" Projects cd Projects # 'pwd' now shows /home/murat/ProjectsThis only worked because I was already in
/home/murat. If I was in/var/logand typedcd Projects, I’d getNo such file or directory.
Beginners often get lost because they don’t know which one to use.
- Use Absolute Paths when you’re writing a script or you know the exact, full path you want to go to, regardless of your current location.
- Use Relative Paths for day-to-day navigation when you’re moving into a folder you can see with
ls.
2. The “Pro” Shortcuts: How to Never Get Lost
Okay, you cd’d into /var/log/nginx/production/archive/2025/, and now you want to get back to your home folder. Do you have to type cd /home/murat? No.
You use the shortcuts.
cd ~(or justcd): The “Teleport Home” Button The tilde (~) character is a special shortcut that always represents your home directory (/home/muratfor me). No matter how deep you are, no matter how lost, this is your “get me home” free card.# 'pwd' shows /var/log/nginx/production/archive/2025/ # Teleport home cd ~ # 'pwd' now shows /home/muratEven faster? Just type
cdwith no argument at all.# 'pwd' shows /var/log/nginx/production/archive/2025/ # Teleport home cd # 'pwd' now shows /home/muratcd ..: The “Go Up One Level” Button Remember whenls -ashowed us.and..? Those are real, usable paths..means “this directory,” and..means “the parent directory.”cd ..is the most common relative path you will ever use. It moves you up one level.# 'pwd' shows /home/murat/Projects/my-blog # Let's go up to the 'Projects' folder cd .. # 'pwd' now shows /home/murat/ProjectsAnd here’s the real pro move: You can chain them.
# 'pwd' shows /home/murat/Projects/my-blog # Let's go up two levels, back to /home/murat cd ../.. # 'pwd' now shows /home/muratcd -: The “Back Button” (The Real Magic) This is it. This is the one I didn’t know about for years. This is the one that will change your life.The dash (
-) is a special shortcut that means “the previous directory I was in.”Imagine this common workflow:
- You’re in your project:
pwdis/home/murat/Projects/my-blog. - You need to check a log file:
cd /var/log/nginx - You read the log. Now… how do you get back to your project?
- Do you re-type
cd /home/murat/Projects/my-blog? No.
You just do this:
# 'pwd' shows /var/log/nginx # Go back to where I just was cd -The shell will show you where it’s taking you and then move you:
/home/murat/Projects/my-blogIt’s a toggle. You can now just type
cd -over and over, and it will flip you back and forth between those two directories. This is the most efficient way to work when you’re bouncing between two locations.- You’re in your project:
Hitting The Wall 🧱
My “wall” was feeling trapped and frustrated. I would follow a tutorial to edit a system config file.
- Me:
cd /etc/nginx/sites-available/ - Me: (I edit the file)
- Me: “Okay, done. Now… uh… how do I get back to my project?”
I was completely, 100% reliant on absolute paths. My fingers would ache from re-typing cd /home/murat/Projects/my-blog/ over and over and over again. I didn’t know about cd -. I barely used cd ~. I would even, embarrassingly, close the terminal and open a new one just to get back to my home directory because it was “faster” than trying to remember the full path.
It made me feel stupid. It made the terminal feel clumsy. I thought, “The GUI is so much faster! I just click my ‘Projects’ folder!” I was blaming the tool when I was the one who didn’t know how to use it. I was using a screwdriver to hammer a nail and getting angry about it.
I also couldn’t get my head around relative vs. absolute paths. I’d be in /home/murat and type cd /Projects (note the leading /) and get No such file or directory. I’d get so mad. “IT’S RIGHT THERE! ls SHOWS IT!” I didn’t understand that the leading / was telling the shell to look in the Root directory, for a folder named Projects, which didn’t exist (it was in /home/murat/Projects).
That one, tiny / was the source of so much of my early frustration.
The Breakthrough Moment ✨
The breakthrough was twofold, and they happened years apart.
The first was cd ... Just realizing that .. wasn’t just “text” from ls but a real place I could cd to was a big step. Chaining it (cd ../..) felt like I had discovered a secret cheat code.
But the real breakthrough, the one that made me feel like a “pro,” was the day I saw a senior engineer use cd -.
He was in a deep project directory. He did cd /var/log to check something. Then, without even thinking, he just typed cd - and bam, he was right back in his project. My jaw dropped. I literally stopped him and said, “What did you just do?”
He just smiled and said, “cd dash. It’s the ‘back’ button. Toggles between your two last directories. Can’t live without it.”
I went back to my desk, and my entire workflow changed in that instant. No more re-typing long paths. No more opening new terminals. I was “in” two places at once. I was in my project, and I was in the log folder, and I could flip between them at the speed of thought.
That, combined with cd ~ (or just cd) to always get home, formed the final, complete mental model.
- I’m never lost, because
cd ~is my “get home free” card. - I never have to re-type, because
cd -is my “go back” button.
I was finally, finally faster than I was in the GUI. I wasn’t lost. I was moving.
📚 Recommended Resource
Once again, I have to recommend “The Linux Command Line: A Complete Introduction” by William Shotts. If my post has you excited about cd, this book is what shows you the map of the city you’ll be navigating. Shotts has brilliant chapters on “Navigation” and, more importantly, on the “Filesystem Hierarchy Standard (FHS).”
You’ll stop wondering why logs are in /var/log (variable data) and configs are in /etc (et cetera). You’ll learn the logic of the map. Knowing why a directory is named what it is and where it lives makes navigating to it 100x more intuitive. It turns navigation from a memorization game into a logical exercise. Amazon
Key Takeaways 📚
- 💡 Complete the Triad: You are now armed with the “Navigational Triad”:
pwd(Where am I?),ls -lah(What’s here?), andcd(How do I move?). With these three commands, you can do 90% of all file system work. - ⚙️ Absolute vs. Relative: This is the core concept. Absolute paths start with
/(a full, exact address). Relative paths do not (local directions from here). 90% of “No such file or directory” errors are caused by mixing these up. - 📚 Master Your “Teleports”: Stop re-typing paths.
cdorcd ~: Instantly go Home.cd ..: Go Up one level (chain it:cd ../..).cd -: Go Back to the last directory you were in. This is your new superpower.
Thanks for Following ☕
☕ If you found this guide helpful, you can Buy Me a Coffee! Medium Etsy LinkedIn Read More
What was your “mind-blown” navigation shortcut? Was it
cd -, or using.., or do you have another one (likepushd/popd) that you love?
