Finding your way around the terminal
pwd, ls and cd, and the mental model that stops the terminal feeling like a haunted house. Part 1 of the Terminal Basics series.
By the end of this tutorial you will know:
- what the terminal is, and why it always has a "current directory"
- how to see where you are (
pwd) and what is around you (ls) - how to move around (
cd) using relative and absolute paths - how to find hidden files
- what the three most common beginner errors mean
Prerequisites: a Linux terminal open and ready. Any distribution will do. If you can find the terminal app in your menu, you are qualified.
How this was checked: every command was run on Ubuntu 24.04 with bash 5.2 and GNU coreutils 9.4, in a real terminal session as an ordinary (non-admin) user, and the output shown is the real output. Your username will differ from ours (gerald), so any path with gerald in it will show your own name instead.
To follow along: open a terminal, type each command, and press Enter. Commands sit in boxes with a Copy button, and their output is in the box directly after.
1. You are always somewhere
The terminal is a window where you type instructions to your computer and it types answers back. There is no mouse, no icons and no sympathy.
Your files live in a tree of folders, which the terminal calls directories. At the very top of the tree is a single directory called / (the root). Everything else branches down from it, including your home directory, usually /home/yourname. That is where you start.
Here is the part nobody tells beginners: the terminal is always standing in exactly one directory, called the working directory. Like a ghost, it haunts one room at a time. When you run a command without saying where, the command acts on the room you are standing in.
Almost every beginner's "why did that not work?" is really "I thought I was in a different room." Learn to ask where am I? and half of your future problems evaporate.
2. Build the practice mansion
Every post in this series practises in the same throwaway folder: a haunted mansion in your home directory. Nothing in it matters, which makes it the safest place on your computer to make mistakes.
Paste this block first. It saves a small setup script. You do not need to understand it yet (a later post unpacks the pieces), but you can read it: it only ever touches a folder called mansion inside your home directory.
cat > ~/mansion-setup.sh <<'SCRIPT'
#!/bin/bash
# Builds the practice mansion in ~/mansion. Safe to run again: it demolishes the
# old mansion first. It only ever touches ~/mansion, never anything else.
rm -rf ~/mansion
mkdir -p ~/mansion/attic/trunk ~/mansion/cellar ~/mansion/kitchen ~/mansion/library
cat > ~/mansion/readme.txt <<'EOF'
Welcome to the mansion.
Please do not wake the guests.
EOF
cat > ~/mansion/attic/cobwebs.txt <<'EOF'
Cobwebs: 4,000.
Spiders: refusing to comment.
EOF
cat > ~/mansion/attic/trunk/love-letters.txt <<'EOF'
Dear Gerald, I loved you in life.
In death, I have notes.
EOF
cat > ~/mansion/cellar/wine-list.txt <<'EOF'
1987 cabernet (gently haunted)
1999 merlot (do not open)
2003 chardonnay (screams a little)
2011 rose (smells of regret)
EOF
cat > ~/mansion/cellar/vault.sh <<'EOF'
#!/bin/bash
echo "The vault is open. It was never locked."
EOF
cat > ~/mansion/kitchen/recipe.txt <<'EOF'
Soup: water, onion, bad decisions.
EOF
cat > ~/mansion/kitchen/complaints.log <<'EOF'
2026-10-30 21:04 INFO the kettle whistled a tune
2026-10-30 22:15 WARN the oven is warm and nobody turned it on
2026-10-31 00:02 ERROR the fridge is screaming
2026-10-31 01:47 WARN the spoons are rearranging themselves
2026-10-31 03:12 ERROR the stove door opened by itself
2026-10-31 03:13 ERROR the stove door closed by itself
2026-10-31 04:30 INFO breakfast was served to nobody
2026-11-01 02:20 WARN the toaster whispered a name
2026-11-01 02:21 ERROR the toaster named a name
2026-11-01 07:00 INFO the kettle whistled a tune
2026-11-02 03:00 ERROR the fridge is screaming
2026-11-02 03:05 INFO the fridge stopped screaming
EOF
cat > ~/mansion/library/diary.txt <<'EOF'
Oct 29: The wallpaper is humming again.
Oct 30: Heard footsteps in the attic. I live alone.
Oct 31: Ghost in the kitchen. Ghost in the cellar. Ghost in the mirror.
Nov 01: Hired an exterminator. He left screaming.
Nov 02: The ghost left a review. One star.
Nov 03: The ghost wants the wifi password.
Nov 04: Gave the ghost the wifi password.
Nov 05: The wifi is slower now.
EOF
cat > ~/mansion/library/guests.txt <<'EOF'
gerald
brenda
gerald
casper
brenda
gerald
morticia
casper
EOF
cat > ~/mansion/library/.boo <<'EOF'
You found the secret passage. It leads to more library.
EOF
# Give everything the same spooky timestamp (Halloween, 3:12 am) so the
# listings in these tutorials match what you see.
find ~/mansion -exec touch -d "2026-10-31 03:12" {} +
echo "The mansion is built. Try not to wake anyone."
SCRIPTNow run the script to build the mansion:
bash ~/mansion-setup.shThe mansion is built. Try not to wake anyone.Why save it as a file? Because every later post begins by rebuilding the mansion from scratch with that same command, so you always start clean even if you wrecked the place last time. If you land here from a later post, run both blocks above and you are caught up.
You should see "The mansion is built. Try not to wake anyone." If you see an error instead, check that you pasted the whole first block, including the final line that says SCRIPT.
3. pwd: where am I?
pwd stands for print working directory. It tells you which room you are standing in:
pwd/home/geraldThat is a path: a list of directories from the top of the tree down to where you are, with a / between each. Read it left to right. Start at the root (/), go into home, then into gerald. That last one is your home directory, which is where every new terminal starts.
Because home is where you spend most of your time, the terminal gives it a shortcut: ~ (a tilde). It means "my home directory". You can see what it stands for with echo, which simply prints whatever you give it:
echo ~/home/gerald4. ls: what is here?
ls lists what is in the working directory:
lsmansion mansion-setup.shTwo names. But which one is a directory and which is a file? Add -F, an option that puts a / after every directory:
ls -Fmansion/ mansion-setup.shAn option is a short flag, starting with a dash, that changes how a command behaves. You can also tell ls to look somewhere else by giving it a path, without moving there:
ls mansionattic cellar kitchen library readme.txt5. cd: move to another room
cd means change directory. Give it the name of a directory and you move there:
cd mansion
pwd/home/gerald/mansionNotice that cd itself printed nothing. When a command works, it often says nothing at all. Silence in the terminal usually means success, which is the opposite of how most haunted houses work.
Look around, then go deeper:
ls
cd library
pwd
lsattic cellar kitchen library readme.txt
/home/gerald/mansion/library
diary.txt guests.txt6. Relative and absolute paths
You have already used two kinds of path without being told.
A relative path starts from where you are. cd library means "from here, go into library". It only works if library is in your working directory.
An absolute path starts from the top (/) or from your home (~), so it works from anywhere. Try jumping straight to the trunk in the attic, no matter where you are:
cd ~/mansion/attic/trunk
pwd/home/gerald/mansion/attic/trunkTwo dots, .., mean "the directory above this one". Use them to climb out:
cd ..
pwd/home/gerald/mansion/atticYou can go up and then down again in one move: up out of the attic, then into the cellar.
cd ../cellar
pwd/home/gerald/mansion/cellarTwo more shortcuts are worth knowing. cd with nothing after it takes you straight home, wherever you are:
cd
pwd/home/geraldAnd cd - takes you back to wherever you just were. It prints the place it takes you to:
cd -/home/gerald/mansion/cellarRun pwd after each move for a while. Seeing the path change after every cd is how you build a feel for the tree. If a path ever surprises you, you have just found out which room you were really in.
7. Hidden files
Files and directories whose names start with a dot are hidden from plain ls. They are usually settings files, and hiding them keeps everyday listings uncluttered. The library has one:
cd ~/mansion/library
lsdiary.txt guests.txtAdd -a (for "all") to reveal them:
ls -a. .. .boo diary.txt guests.txtThere it is: .boo, the secret passage. You will also see two odd entries, . and ... They are not real files. They are the shortcuts you met earlier: . means "this directory" and .. means "the directory above".
8. The three errors you will see first
You will mistype something within the hour. Here are the three errors you will meet first, so they are old friends by then. Start from the mansion's front hall:
cd ~/mansion
cd nopebash: cd: nope: No such file or directoryThat one says the directory does not exist. Check the spelling, and check which room you are in. It also cares about capital letters, because to the terminal library and Library are different things:
cd Librarybash: cd: Library: No such file or directoryAnd if you try to cd into something that is a file, not a directory:
cd readme.txtbash: cd: readme.txt: Not a directoryAnd if you mistype the command itself, the terminal has no idea what you are asking for:
lssbash: lss: command not found| Error | What it usually means | Fix |
|---|---|---|
No such file or directory | That name does not exist where you are | Check the spelling, the capital letters, and pwd |
Not a directory | You tried to cd into a file | Use ls -F to see what is a directory |
command not found | The command name is mistyped, or not installed | Check the spelling of the command itself |
Practice
Predict the answer before you run each one. Answers follow.
Exercise 1. You are in ~/mansion/attic/trunk. What single command takes you to ~/mansion/library without typing the whole path?
Exercise 2. Where does cd ~/mansion/kitchen/.. take you?
Exercise 3. From ~/mansion, how do you list the hidden files in library without moving into it?
Answers
Exercise 1. Climb up twice, then down into the library:
cd ~/mansion/attic/trunk
cd ../../library
pwd/home/gerald/mansion/library.. takes you from trunk to attic, and the second .. from attic to mansion, and then library goes down from there.
Exercise 2. Into the kitchen, then straight back up, so you end up in the mansion:
cd ~/mansion/kitchen/..
pwd/home/gerald/mansionExercise 3. Give ls the -a option and the path of the room you want to peek into:
cd ~/mansion
ls -a library. .. .boo diary.txt guests.txtWhat you learned
- The terminal always stands in one working directory, and
pwdtells you which. lslists what is there.-Fmarks directories with a/, and-areveals hidden files.cdmoves you. A relative path starts from where you are, and an absolute path starts from/or~and works from anywhere...is the directory above,~is home, plaincdgoes home, andcd -goes back.- When a command works it often prints nothing. Errors are specific, and they are usually just a misspelling or the wrong room.
Next in the series: Making, moving and deleting files. You will learn to create, copy, rename and destroy things, in a mansion built for exactly that.