PLAINFINCH learn by building

Moving around

You will move between folders by typing short paths, jump back to where you were, and find your way home when lost.

What does cd actually change?

cd, change directory, moves your shell into another folder. Nothing on disk changes. It only sets the working directory, the starting point that every following command uses for names that don’t begin with /. That’s why cd prints nothing when it works: the only evidence is the prompt changing and what pwd says next.

Each terminal window has its own working directory. Open a second window and it starts at home again, whatever the first one is doing. A script you run starts in the folder you ran it from, and when it uses cd inside, your own shell stays where it was.

What is the difference between absolute and relative paths?

An absolute path starts with / and spells out the route from the very top: /home/you/spoke-and-chain/repairs/2026/march. It means the same folder whatever directory you type it in. That makes it the safe choice in scripts, in notes for other people, and any time you’re not sure where you are.

A relative path has no leading / and starts from the working directory. In ~/spoke-and-chain, repairs/2026/march reaches the same folder in fewer keystrokes. From somewhere else, the same text points somewhere else or nowhere. The shell never guesses: if the name isn’t under where you are, cd fails with “No such file or directory”.

Paths starting with ~ count as absolute. The shell swaps ~ for your home folder before cd sees it, so cd ~/spoke-and-chain works the same from /tmp, from deep inside the repairs, or from anywhere.

cd /home/you/spoke-and-chain/website   # absolute: works anywhere
cd ~/spoke-and-chain/website           # also works anywhere
cd website                             # relative: only from ~/spoke-and-chain

How do .. and . work?

Every folder contains two special entries. .. means the folder one level up, the parent. . means this folder. cd .. climbs one level; cd ../.. climbs two. You can mix them with ordinary names: from ~/spoke-and-chain/website/images, the path ../../repairs/2026/march goes up to website, up to spoke-and-chain, then down three levels.

Count levels by reading the path from pwd. Each .. removes the last part. /home/you/spoke-and-chain/website/images with one .. becomes .../website, with two becomes .../spoke-and-chain. You’ll rarely need . with cd, but it shows up when running scripts, as in ./tidy.sh, which means “the tidy.sh in this folder”.

At the very top, .. points back to / itself, so cd .. from / does nothing and gives no error.

$ pwd
/home/you/spoke-and-chain/website/images
$ cd ../../repairs/2026/march
$ pwd
/home/you/spoke-and-chain/repairs/2026/march
FigureA folder tree inside spoke-and-chain. Starting in website/images, the path climbs two levels with .. to spoke-and-chain, then goes down through repairs and 2026 to march.A folder tree inside spoke-and-chain. Starting in website/images, the path climbs two levels with .. to spoke-and-chain, then goes down through repairs and 2026 to march.
The relative path from images to march: two steps up to spoke-and-chain, then three steps down. pwd before and after shows where you started and where you landed.

What do ~ and cd on its own do?

cd with no folder after it takes you home, and so does cd ~. When you’re lost, that’s the reset button: go home, run ls, and start again from names you know.

~ works inside longer paths as well, and with other commands: ls ~/bird-club or cat ~/notes.txt work wherever you are. On a real system ~name means another user’s home folder, such as ~ann; you’ll mostly see that on shared servers. The tilde is only expanded at the start of a word and outside quotes, so cd "~/spoke-and-chain" looks for a folder literally called ~.

How does cd - help?

cd - takes you back to the folder you were in before the last cd, and prints its full path so you can see where you landed. Use it again and you’re back where you started. It’s ideal when you’re switching between two folders, such as the website you’re editing and the log you’re checking.

It only remembers one step. After cd a, cd b, cd c, the command cd - takes you to b, and a second cd - takes you to c again, never to a. Bash keeps that previous folder in a variable called OLDPWD; the Environment variables lesson shows how to look at it.

$ cd -
/home/you/spoke-and-chain/website/images
$ cd -
/home/you/spoke-and-chain/repairs/2026/march

What about names with spaces?

The shell splits what you type at spaces, so cd hire bikes hands cd two words, hire and bikes. Older versions of bash try the first word and report bash: cd: hire: No such file or directory, which is what the practice terminal shows. Bash 5, on most current Linux servers, says bash: cd: too many arguments instead. Both mean the space split the name.

Wrap the name in quotes, cd "hire bikes", or put a backslash before the space, cd hire\ bikes. Tab completion adds the backslash for you, which is one more reason to press Tab. Better still, name your own folders with hyphens, hire-bikes, and the problem never comes up.

$ cd hire bikes
bash: cd: hire: No such file or directory
$ cd "hire bikes"

How do you avoid getting lost?

Read the prompt before each command, and run pwd when it’s cut short or hidden. Use Tab after each part of a path: if Tab won’t complete, the name isn’t there, and you’ve found the problem before pressing Enter. When a relative path gets long, such as ../../../, an absolute path starting with ~ is often easier to get right first time.

The Files view next to the practice terminal marks where you are. On a real computer, ls after every cd gives you the same reassurance. These habits matter most on a server, where rm in the wrong folder deletes real files.

What do AI tools get wrong here?

AI replies often say “cd into your project” and then give relative paths that only make sense from one particular folder. If a step says cd src, check first with pwd and ls that src is right there.

They also chain cd commands that depend on each other, such as cd .. three times. If one fails, the rest run from the wrong place. A script that does cd build and then deletes files is the classic accident: when build doesn’t exist, the cd fails, the shell carries on, and the delete runs in whatever folder you were already in. Writing cd build && ... stops at the first failure, and the Scripts lesson comes back to this. Doing it in one go with an absolute path, cd ~/spoke-and-chain/website, either works or fails clearly. Watch for Windows habits too: cd \Users\you with backslashes and drive letters like C: mean nothing to bash. On Windows with WSL, your C drive is at /mnt/c.

Field notes

  • Changing folder moves only your shell; nothing on disk changes.
  • An absolute path starts with /; a relative one starts from where you are.
  • .. means the folder above, and cd on its own takes you home.
  • cd - switches back to the folder you were in just before.

Easy to get wrong

Inside quotes the ~ isn’t expanded, so the shell looks for a folder literally named ~. Quote only the part with spaces: cd ~/"hire bikes".

The space splits the name into two arguments. Quotes or a backslash keep it together.

Commands and their arguments need a space between them. Without it, bash treats cd../.. as one word, the name of something to run, and fails.

A leading / starts from the top of the computer, where there is no spoke-and-chain. Your folders live under ~.

Questions people ask

Why does cd print nothing?

Commands that succeed usually stay silent. The prompt changing is your confirmation, and pwd gives the full path if you want it. cd - is the exception and prints where it took you.

Can I go back more than one folder?

Not with cd -. Bash has pushd and popd for a stack of folders, but most people use absolute paths with ~ instead. The practice terminal doesn’t include pushd.

Is this the same on a Mac?

Yes. cd, .., ~ and cd - behave the same in zsh. Your home folder there is /Users/yourname.

What does cd do with a file name?

It fails with “Not a directory”. You can only move into folders; read files with cat, less or head instead.

Keep going