The Command Line
Learn to navigate your computer using the terminal — the essential tool every developer and tester needs.
What you'll learn
- Open a terminal on your computer
- Navigate between folders using cd, ls, and pwd
- Create, rename, and delete files and folders
- Understand absolute vs relative paths
Playwright AutomationlessonsJump to another lesson
The Command Line
Instead of clicking icons, you can type commands to control your computer. That’s the terminal.
Two Ways To Do The Same Thing
Opening a folder with your mouse vs. opening it with the keyboard. Same result, very different speed.
GUI (mouse)
Point. Click. Click. Click.
CLI (typing)
Type. Enter. Done.
Both work. But the CLI version is faster, scriptable, and works over SSH — which is why every dev and QA engineer learns it.
Opening the Terminal
- 1
Mac: Spotlight
Press Cmd + Space, type 'Terminal', press Enter.
- 2
Mac: Finder
Applications → Utilities → Terminal.
- 3
Windows: PowerShell
Click Start, type 'PowerShell', click Windows PowerShell. (Windows Terminal also works great.)
When it opens, you’ll see a prompt — a blinking cursor waiting for your command.
yourname@computer ~ %# Mac / Linux prompt ↑PS C:\Users\YourName># Windows PowerShell prompt ↑Try it in your terminal!
pwd — Where am I?
# Print Working Directory — shows which folder you are in$ pwd/Users/yournameTry it in your terminal!
ls — What’s in here?
$ lsDesktop Documents Downloads Music PicturesTry it in your terminal!
Same folders you’d see in Finder or File Explorer — just as text.
cd — Go somewhere
# Go into a folder$ cd Documents$ pwd/Users/yourname/Documents# Go back up one level$ cd ..# Jump straight home$ cd ~# Go to the root of the whole file system$ cd /Try it in your terminal!
Quick check
What does 'cd ~' do?
Absolute vs Relative Paths
Absolute Path
- Full address from the root
- Starts with / (or C:\)
- Works from anywhere
- Example: /Users/you/Documents/notes.txt
Relative Path
- Starts from where you are
- Shorter — less typing
- Depends on current folder
- Example: ./Documents/notes.txt
VerdictUse relative paths for quick navigation. Use absolute paths in scripts and config files.
Relative shortcuts:
./— current folder../— up one level../../— up two levels
Works from anywhere. Full address from the root /.
Only works from your home folder. Shorter — but depends on where you are.
mkdir — Create a folder
$ mkdir my-project# Created an empty folder called my-project$ mkdir -p my-project/src/tests# -p flag creates parent folders tooTry it in your terminal!
Creating files
# Mac / Linux$ touch hello.txt# Windows PowerShell$ New-Item hello.txtTry it in your terminal!
rm — Delete (DANGER!)
# Delete a file$ rm hello.txt# Delete a folder and everything inside (-r = recursive)$ rm -r my-folderTry it in your terminal!
mv — Move or rename
# Move a file$ mv hello.txt Documents/# Rename a file$ mv old-name.txt new-name.txtTry it in your terminal!
cp — Copy
$ cp hello.txt hello-backup.txt# Copy a whole folder with -r$ cp -r my-project my-project-backupTry it in your terminal!
clear — Clean up the screen
$ clear# Screen is now fresh — shortcut: Ctrl + LTry it in your terminal!
Common Mistakes
Pro Tips
Quick check
You want to cd into a folder called 'Documents' but hate typing. What's the fastest way?
Quick Reference
| Command | What it does | Example |
|---|---|---|
pwd | Print where you are | pwd |
ls | List files and folders | ls |
cd | Change directory | cd Documents |
cd .. | Go up one level | cd .. |
cd ~ | Go to home directory | cd ~ |
mkdir | Create a folder | mkdir my-project |
touch | Create a file (Mac/Linux) | touch app.js |
rm | Delete a file | rm old-file.txt |
rm -r | Delete a folder | rm -r old-folder |
mv | Move or rename | mv old.txt new.txt |
cp | Copy | cp file.txt backup.txt |
clear | Clear the screen | clear |
Practice Exercises
To see which folder you're currently in, type
Put these commands in the correct order to: create a project folder, go into it, and create a file inside it.
- 1touch app.js
- 2cd my-project
- 3mkdir my-project