The Command Line

Learn to navigate your computer using the terminal — the essential tool every developer and tester needs.

Playwright Automation Prep Lesson 1
15 min read

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

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.

Click Documents folder
Documents
Click Projects folder
Projects
my-project
Three clicks. Your hand left the keyboard.

CLI (typing)

Type. Enter. Done.

# Same thing, typed:
$ cd Documents
$ cd Projects
$ cd my-project
# You are here. Fingers never moved.

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. 1

    Mac: Spotlight

    Press Cmd + Space, type 'Terminal', press Enter.

  2. 2

    Mac: Finder

    Applications → Utilities → Terminal.

  3. 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.

The prompt
yourname@computer ~ %# Mac / Linux prompt ↑PS C:\Users\YourName># Windows PowerShell prompt ↑

Try it in your terminal!

pwd — Where am I?

pwd
# Print Working Directory — shows which folder you are in$ pwd/Users/yourname

Try it in your terminal!

ls — What’s in here?

ls
$ lsDesktop    Documents    Downloads    Music    Pictures

Try it in your terminal!

Same folders you’d see in Finder or File Explorer — just as text.

cd — Go somewhere

Moving around
# 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

Question 1 of 10 correct

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
absolute path
"/Users/you/Documents/notes.txt"

Works from anywhere. Full address from the root /.

relative path
"./Documents/notes.txt"

Only works from your home folder. Shorter — but depends on where you are.

mkdir — Create a folder

mkdir
$ mkdir my-project# Created an empty folder called my-project$ mkdir -p my-project/src/tests# -p flag creates parent folders too

Try it in your terminal!

Creating files

Create an empty file
# Mac / Linux$ touch hello.txt# Windows PowerShell$ New-Item hello.txt

Try it in your terminal!

rm — Delete (DANGER!)

rm
# Delete a file$ rm hello.txt# Delete a folder and everything inside (-r = recursive)$ rm -r my-folder

Try it in your terminal!

mv — Move or rename

mv does two jobs
# Move a file$ mv hello.txt Documents/# Rename a file$ mv old-name.txt new-name.txt

Try it in your terminal!

cp — Copy

cp
$ cp hello.txt hello-backup.txt# Copy a whole folder with -r$ cp -r my-project my-project-backup

Try it in your terminal!

clear — Clean up the screen

clear
$ clear# Screen is now fresh — shortcut: Ctrl + L

Try it in your terminal!

Common Mistakes

Pro Tips

Quick check

Question 1 of 10 correct

You want to cd into a folder called 'Documents' but hate typing. What's the fastest way?

Quick Reference

CommandWhat it doesExample
pwdPrint where you arepwd
lsList files and foldersls
cdChange directorycd Documents
cd ..Go up one levelcd ..
cd ~Go to home directorycd ~
mkdirCreate a foldermkdir my-project
touchCreate a file (Mac/Linux)touch app.js
rmDelete a filerm old-file.txt
rm -rDelete a folderrm -r old-folder
mvMove or renamemv old.txt new.txt
cpCopycp file.txt backup.txt
clearClear the screenclear

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.

  1. 1touch app.js
  2. 2cd my-project
  3. 3mkdir my-project

Check Your Understanding

Question 1 of 30 correct

You are in /Users/yourname/Documents/projects. You want to go to /Users/yourname/Documents. What do you type?