Skip to main content

Terminal Navigation: Getting Around

Navigation is moving through directories. That's it. But it's what you'll do constantly.

Here's the thing: Once navigation is automatic, you can focus on what you're doing, not where you are.

Understanding Paths

Absolute vs Relative

Absolute path: Full path from root.

/home/ubuntu/Documents/file.txt

Relative path: Path from where you are.

Documents/file.txt                # If you're in /home/ubuntu
../Downloads/file.txt # Up one level, then Downloads

My take: Absolute paths are clear. Relative paths are shorter. Use both.

Path Components

/home/ubuntu/Documents/file.txt
│ │ │ │ │
│ │ │ │ └─ Filename
│ │ │ └─────────── Directory
│ │ └────────────────── Username
│ └──────────────────────── Home
└───────────────────────────── Root

My take: Understanding paths helps. But you'll learn by doing. Don't overthink it.

Essential Navigation

pwd: Where Am I?

pwd

What it does: Shows current directory.

When to use: When you're lost. Or before important operations.

My take: Use pwd when you're not sure. It's your anchor.

cd: Moving Around

cd /path/to/dir                   # Absolute path
cd dirname # Relative path
cd ~ # Home directory
cd # Also home
cd .. # Up one level
cd ../.. # Up two levels
cd - # Previous directory

The ~: Shorthand for home directory. You'll use it constantly.

The cd -: Goes back to where you were. Underrated feature.

Real examples:

cd ~                              # Go home
cd /etc # Go to /etc
cd .. # Go up
cd - # Go back

My take: cd is simple. But learn the shortcuts. They save time.

Tab Completion

cd /hom<Tab>                      # Completes to /home/
cd /home/ub<Tab> # Completes to /home/ubuntu/

What it does: Completes paths automatically.

My take: Use tab completion. Always. It's faster. Prevents typos.

Home Directory

cd ~                              # Go home
cd # Also go home

My take: ~ is home. Use it. Remember it.

Previous Directory

cd -                              # Go back

My take: cd - is useful. Jump between two directories easily.

Parent Directory

cd ..                             # Up one level
cd ../.. # Up two levels

My take: .. is parent. Use it to go up.

Common Patterns

cd ~                              # Home
cd /etc # Configuration
cd /var/log # Logs
cd /tmp # Temporary

My take: Learn common paths. You'll go there often.

cd /path && ls -la                # Go and list

My take: Combine commands. && runs second if first succeeds.

cd "$(dirname "$0")"              # Script's directory
cd "$HOME/projects" # User's projects

My take: Use variables in scripts. Makes them portable.

Common Mistakes (I've Made These)

  1. Spaces in paths: cd my folder doesn't work. Use quotes: cd "my folder" or escape: cd my\ folder.

  2. Case sensitivity: cd /Home doesn't work if it's /home. Linux cares about case.

  3. Forgetting ~: cd ~ is shorter than cd /home/username. Use it.

  4. Not using tab completion: Type less. Complete more. Use tab.

  5. Relative vs absolute confusion: When in doubt, use absolute paths.

Real-World Examples

cd /var/log
ls -la
cd /etc/nginx
ls -la
cd ~/projects && ./build.sh

What's Next?

Now that you can navigate, you can go anywhere. Or learn about Essential Commands to actually do things.


Personal note: When I started, I'd type full paths constantly. Then I learned shortcuts. Now I navigate quickly. Navigation becomes automatic. Practice it. It's worth it.