Before you can do anything useful in the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell., you need to understand how to move around. Think of your computer's file system like a city. You have main streets (root directories), neighborhoods (folders), and buildings (files). Right now, you are somewhere in this city, but you need to know exactly where before you can navigate to your destination.
Knowing where you are: pwd
The most fundamental question in navigation is: "Where am I?" In the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell., pwd answers that.
pwd
# Output: /Users/sarah/DocumentsThat is your absolute path: your exact coordinates in the file system. It starts from the root (/) and traces the complete route to your current location.
Seeing what is around you: ls
Once you know where you are, you want to see what is here. That is what ls does, it lists the contents of your current directory.
ls
# Output: Desktop Documents Downloads Music PicturesMaking ls more useful with flags
The basic ls is fine, but flags make it much more informative.
| Flag | What it does | Why use it |
|---|---|---|
-a | Show all files, including hidden ones | See config files like .bashrc |
-l | Long format with details | Shows permissions, sizes, dates |
-h | Human-readable sizes | Shows "1.5K" instead of "1536" |
-la | Combine both flags | Everything, with full details |
ls -la
# drwxr-xr-x 12 sarah staff 384B Jan 15 10:32 .
# drwxr-xr-x 5 sarah staff 160B Jan 10 09:15 ..
# -rw-r--r-- 1 sarah staff 220B Jan 14 16:20 .bashrc
# drwxr-xr-x 8 sarah staff 256B Jan 15 09:00 DocumentsFiles that start with a dot (.) are hidden by default. They are usually configuration files, .bashrc, .gitignore, .ssh/. The -a flag reveals them.
Moving between directories: cd
cd stands for "Change Directory." It is how you move from one folder to another.
cd Documents # Enter a subdirectory
cd .. # Go up one level
cd ~ # Go to home directory
cd - # Go back to previous directory
cd ../.. # Go up two levelscd /Users/sarah/Documents/Projects/my-app when a simple cd ~/Projects/my-app or even cd Projects/my-app (relative) would work. It also forgets about spaces in filenames, you need quotes or backslashes: cd "My Documents" or cd My\ Documents. Without them, the shell treats each word as a separate argument.Absolute vs relative paths
This is where many beginners get confused. Let us clear it up.
An absolute path always starts with / (the root). It works from anywhere because it specifies the complete route from the top. Think of it as a full postal address.
cd /Users/sarah/Documents/Projects/my-app
cd /var/logA relative path does not start with /. It starts from your current location. Think of it as giving directions: "turn left, then right", those directions depend on where you start.
cd Documents # Go into Documents from here
cd ../Desktop # Go up one level, then into Desktop
cd src/components # Go into src, then into componentsSpecial path symbols
| Symbol | Meaning | Example usage |
|---|---|---|
. | Current directory | ./script.sh (run script here) |
.. | Parent directory (up one level) | cd .. or ../config.json |
~ | Home directory | ~/Documents or cd ~ |
- | Previous directory | cd - (go back) |
A real-world navigation example
Imagine you are in your home folder and you want to get to /Users/you/Documents/Projects/my-app. You have several options:
# Step by step (good for learning, tedious daily)
cd Documents && cd Projects && cd my-app
# One relative path (fast from home)
cd Documents/Projects/my-app
# Absolute path (works from anywhere)
cd /Users/you/Documents/Projects/my-app
# Home shortcut (best of both worlds)
cd ~/Documents/Projects/my-appTab completion: your secret weapon
Never type full paths when you can press Tab. Start typing a path, then press Tab:
cd Doc<Tab> # Completes to: cd Documents
cd Do<Tab><Tab> # Shows: Documents/ Downloads/
cd /us<Tab>/bi<Tab> # Expands to: cd /usr/binTab completion works on directory names, file names, command names, Git branches, and basically everything in the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell..
Quick reference
| Command | What it does | Example |
|---|---|---|
pwd | Show current directory | pwd |
ls | List files and folders | ls or ls -la |
cd folder | Enter a directory | cd Documents |
cd .. | Go up one level | cd .. |
cd ~ | Go to home directory | cd ~ |
cd - | Go to previous directory | cd - |
cd /path | Absolute navigation | cd /var/log |