Moving Around

Table of Contents

  1. You Are Always Somewhere
  2. Where Am I? pwd
  3. What's Here? ls
  4. Going Somewhere: cd
  5. Absolute and Relative Paths
  6. The Special Names: ~, ., and ..
  7. Your Windows Files from WSL and Git Bash
  8. Setting Up Your Practice Folder
  9. Try It Yourself

1. You Are Always Somewhere

In a file manager, you always have a folder open — you can see its name at the top of the window. The shell works the same way: at every moment, it has one folder open, called the current working directory (or just the current directory).

Every command you run happens in that folder. When you type ls with no argument, it lists the current directory. When you create a file without saying where, it's created in the current directory. When a tutorial says "run npm install in the project folder", it means "make the project folder your current directory first, then run it".

So the three most basic questions on the command line are:

  • Where am I? → pwd
  • What's here? → ls
  • How do I go somewhere else? → cd

2. Where Am I? pwd

pwd stands for print working directory:

pwd
/Users/dara

When you open a new terminal, you almost always start in your home folder — the folder that belongs to your user. Where it lives depends on the system:

SystemHome folder
macOS/Users/dara
Linux and WSL/home/dara
Git Bash/c/Users/dara

The output of pwd is an absolute path — the full address of the folder, starting from the root /. You first met paths in Files and File Systems; now you'll use them for real.

3. What's Here? ls

You already know ls lists the contents of a folder. A few options make it far more useful:

ls        # names only
ls -a     # include hidden files (names starting with a dot)
ls -l     # long format: one item per line, with details
ls -lh    # long format, with human-readable sizes (K, M, G)

The long format looks like this:

drwxr-xr-x   5 dara  staff   160 Sep 28 14:02 Documents
-rw-r--r--   1 dara  staff  2.1K Sep 30 09:15 notes.txt

For now, focus on three parts:

  • The first character: d means it's a directory (folder), - means it's a regular file.
  • The size (2.1K) and date it was last modified.
  • The name, at the end.

The rest — rwxr-xr-x, dara, staff — are permissions and ownership. Chapter 10 explains them.

You can also list a folder without going into it, by passing it as an argument:

ls -l Documents

4. Going Somewhere: cd

cd means change directory. Give it the folder you want to go to:

cd Documents
pwd
/Users/dara/Documents

Notice that cd prints nothing when it works. On the command line, silence usually means success. The prompt also changes to show the new folder, which is a nice reminder of where you are.

Use Tab here constantly. Type cd Doc, press Tab, and the shell completes it to cd Documents/. You can keep going: type the first letters of the next folder and press Tab again.

You can also move several levels at once by joining folder names with /:

cd projects/my-app/src

5. Absolute and Relative Paths

There are two ways to tell cd (or any command) where something is:

An absolute path starts with / and gives the full address from the root. It works no matter where you currently are:

cd /Users/dara/projects/my-app

A relative path doesn't start with /. It's taken relative to your current directory:

cd projects/my-app

This only works if projects is inside the folder you're in right now. If you're somewhere else, you'll get:

cd: no such file or directory: projects/my-app

That's the most common beginner error on the command line, and now you know what it means: the path was relative, and you weren't where you thought you were. Run pwd to check.

A simple rule: use relative paths for moving around nearby (short and quick), and absolute paths when you need something to work from anywhere — like in a script or in documentation.

6. The Special Names: ~, ., and ..

Three short names show up everywhere:

NameMeansExample
~Your home foldercd ~/Documents works from anywhere
.The current folderls . is the same as ls
..The parent folder — one level upcd .. goes up one level

Going up is something you'll do constantly:

pwd
/Users/dara/projects/my-app/src
cd ..
pwd
/Users/dara/projects/my-app

You can chain .. to go up several levels, or go up and then back down into a sibling folder:

cd ../..             # up two levels
cd ../other-app      # up one level, then into other-app

Two more shortcuts worth knowing:

cd        # with no argument: go straight back to your home folder
cd -      # go back to the folder you were in before (like a "back" button)

cd - is surprisingly handy when you're switching between two folders over and over.

Why . matters: it looks pointless now, but you'll see it a lot. code . opens the current folder in VS Code, docker build . builds from the current folder, and ./setup.sh runs a script that's in the current folder (chapter 10 explains why the ./ is needed).

7. Your Windows Files from WSL and Git Bash

If you're on Windows, your normal files — Desktop, Documents, Downloads — live on the Windows side. You can still reach them:

  • WSL: Windows drives appear under /mnt. Your Windows home folder is /mnt/c/Users/<your-windows-name>.
  • Git Bash: drives appear as /c, /d, and so on. Your home folder is already /c/Users/<you>.

For WSL, a good habit: keep your code projects inside the Linux home folder (~), not under /mnt/c. Tools like Node.js and Git run much faster there.

To open the current folder in your normal file manager:

open .           # macOS
xdg-open .       # Linux
explorer.exe .   # WSL and Git Bash

This is a great way to check that what the terminal shows and what you see in the file manager are the same thing — because they are.

8. Setting Up Your Practice Folder

From here on, every exercise in this series happens in one folder: ~/cli-practice. Keeping practice in its own folder means that even if you make a mistake with a command like rm (chapter 4), only your practice files are at risk.

Run these commands one at a time:

cd ~
mkdir cli-practice
cd cli-practice
mkdir notes projects photos
ls
notes    photos   projects

mkdir means make directory. The first one creates cli-practice in your home folder; the second creates three folders at once inside it. You'll learn everything mkdir can do in the next chapter — for now, let's just use it to have somewhere to move around.

Now try moving through it:

cd projects
pwd
cd ..
cd photos
cd ../notes
pwd
cd ~
cd cli-practice

At every step, glance at your prompt or run pwd to confirm where you are. It quickly becomes automatic.

9. Try It Yourself

  1. Open a new terminal and run pwd. Is it your home folder?
  2. Run ls -la in your home folder. Which items are folders (d) and which are files (-)?
  3. Use cd and Tab to go into ~/cli-practice/projects without typing any full folder name.
  4. From inside projects, get to photos using a relative path in a single cd command. Then do the same with an absolute path.
  5. Run cd on its own, then cd -. Where did you end up each time?
  6. Run open ., xdg-open ., or explorer.exe . (depending on your system) inside cli-practice, and compare the window with ls.

You can now find your way around the file system without a mouse. Next, let's start creating, copying, moving, and deleting files.

Buy Me a Coffee

Found this tutorial helpful? Consider buying me a coffee to support more free content!