Skip to content

Module 0.3: First Terminal Commands

Hands-On Lab Available
Ubuntu beginner 20 min
Launch Lab ↗

Opens in Killercoda in a new tab

Complexity: [QUICK] - Follow along and type what you see

Time to Complete: 25 minutes

Prerequisites: Module 0.1 - What is a Computer?


After this module, you will be able to:

  • Navigate the file system using pwd, ls, and cd without getting lost
  • Create files and directories, and explain the difference between cp and mv
  • Delete files safely with rm and explain why there is no undo
  • Combine commands using pipes (|) to filter and search output

The terminal is how professionals talk to computers. Clicking buttons in a graphical interface is fine for everyday tasks, but when you need to manage servers, automate work, or use Kubernetes, the terminal is your primary tool.

Here’s the thing: the terminal isn’t harder than a graphical interface. It’s just different. Instead of clicking a folder to open it, you type a command. Instead of dragging a file to move it, you type a command. Same actions, different method.

By the end of this module, you’ll know the 9 commands that cover about 80% of everyday terminal work.


Before we begin, you need to actually open a terminal.

macOS: Press Cmd + Space, type “Terminal”, press Enter. (Or find it in Applications > Utilities > Terminal.)

Windows: Search for “PowerShell” in the Start menu. (Most commands below work in PowerShell. For full compatibility, install Windows Terminal and WSL — but don’t worry about that today.)

Linux: Press Ctrl + Alt + T on most systems, or search for “Terminal” in your applications.

You should see something like this:

username@computername ~ $

That $ (or % on some Macs) is the prompt. It means the terminal is waiting for you to type something. Think of it as the kitchen staff saying “Order, please!”


Your File System: The Restaurant Floor Plan

Section titled “Your File System: The Restaurant Floor Plan”

Before we start running commands, you need to understand one thing: your computer organizes files in a tree structure. Think of it like rooms in a building.

/ (the root -- the building itself)
├── Users/
│ └── yourname/ ← This is your "home directory"
│ ├── Desktop/
│ ├── Documents/
│ ├── Downloads/
│ └── Pictures/
├── Applications/
└── System/

Every file lives somewhere in this tree. Commands let you move through the tree, see what’s in each room, and create or remove things.


pwd stands for Print Working Directory. It tells you where you are right now.

Think of it as asking: “What room am I in?”

Terminal window
pwd

Expected output:

/Users/yourname

(On Linux, it might be /home/yourname. On Windows PowerShell, something like C:\Users\yourname.)

This is your home directory — your personal space in the computer. It’s like your own private office in the restaurant.

When to use it: Whenever you’re not sure where you are. Even experienced engineers type pwd constantly. There’s no shame in checking.


ls stands for List. It shows you what’s in your current directory (room).

Terminal window
ls

Expected output (yours will be different):

Desktop Documents Downloads Music Pictures

Want more details? Add the -l flag (that’s a lowercase L, for “long format”):

Terminal window
ls -l

Expected output:

drwx------ 4 yourname staff 128 Mar 15 10:30 Desktop
drwx------ 5 yourname staff 160 Mar 20 09:15 Documents
drwx------ 12 yourname staff 384 Mar 22 14:45 Downloads

Don’t worry about understanding every column yet. The important parts are the name (rightmost) and the date (when it was last changed).

Try it yourself: Run ls in your home directory. Now run ls -l. What extra information do you see? You should notice dates, sizes, and some cryptic letters on the left. Don’t worry about understanding all of it yet — just notice that the -l flag gives you more detail than plain ls.

Want to see hidden files too? (Files starting with a dot, like .bashrc, are hidden by default.)

Terminal window
ls -la

The -a means “all” — show everything, including hidden files.


cd stands for Change Directory. It moves you to a different room.

Terminal window
cd Documents

Now check where you are:

Terminal window
pwd

Output:

/Users/yourname/Documents

You moved! You’re now “inside” the Documents folder.

Pause and predict: If cd Documents moves you forward into the Documents folder, what command do you think you would use to go backward out of it?

The .. means “the parent directory” — the room that contains this room.

Terminal window
cd ..
Terminal window
pwd

Output:

/Users/yourname

You’re back in your home directory.

No matter where you are in the file system, cd ~ takes you home. The ~ symbol (called “tilde”) is a shortcut for your home directory.

Terminal window
cd ~

This is like having a “return to base” button. Use it whenever you get lost.

Going to a specific place: cd /path/to/place

Section titled “Going to a specific place: cd /path/to/place”

You can jump directly to any location by typing the full path:

Terminal window
cd /tmp
Terminal window
pwd

Output:

/tmp

Now go back home:

Terminal window
cd ~

Command 4: mkdir — “Build a New Room”

Section titled “Command 4: mkdir — “Build a New Room””

mkdir stands for Make Directory. It creates a new folder.

Terminal window
mkdir my-first-folder

Check that it worked:

Terminal window
ls

You should see my-first-folder in the list.

What if you want to create a folder inside a folder inside a folder? The -p flag (for “parents”) creates the entire path at once:

Terminal window
mkdir -p restaurant/kitchen/prep-area

This creates three folders nested inside each other, even though restaurant and kitchen didn’t exist yet.


Command 5: touch — “Create an Empty File”

Section titled “Command 5: touch — “Create an Empty File””

touch creates an empty file. (Technically, it updates a file’s timestamp, but if the file doesn’t exist, it creates it.)

Terminal window
touch menu.txt

Check:

Terminal window
ls

You’ll see menu.txt in your list. It’s empty — just a blank piece of paper waiting to be written on.


cp stands for Copy. It makes a duplicate of a file.

Terminal window
cp menu.txt menu-backup.txt

Now you have two files: the original and the copy.

Terminal window
ls

Output:

menu-backup.txt menu.txt my-first-folder restaurant

To copy a file into a folder:

Terminal window
cp menu.txt restaurant/

To copy an entire folder (and everything inside it), use -r (for “recursive” — meaning “this folder and everything in it”):

Terminal window
cp -r restaurant restaurant-copy

mv stands for Move. It does two things:

Moving a file to another folder:

Terminal window
mv menu-backup.txt restaurant/

The file is no longer here — it’s been moved into the restaurant folder. Unlike cp, the original doesn’t stay behind.

Renaming a file:

Terminal window
mv menu.txt daily-specials.txt

The file menu.txt is gone. In its place is daily-specials.txt. Same file, new name. Moving and renaming are the same operation — you’re just changing where (or what) the file is called.


Stop and think: When you delete a file by dragging it to the Trash on your desktop, where does it go? You can still recover it, right? Now think — what do you think happens when you delete a file in the terminal? Is there a Trash can? Take a guess before reading.

rm stands for Remove. It deletes a file.

Terminal window
rm daily-specials.txt

The file is gone.

This is the most important thing in this entire module:

rm does not move files to a trash can. It deletes them permanently. There is no undo. There is no “Are you sure?” prompt. The file is gone.

Real-World War Story: In 1998, Pixar almost lost the entire movie Toy Story 2. An animator accidentally ran rm -r * at the root level of the project. Because there is no “Trash” in the terminal, the system immediately began permanently deleting character models, environments, and animations. They unplugged the server to stop it, but 90% of the film’s files were already gone. They only survived because the technical director had a personal backup on her home computer! This illustrates the sheer unforgiving power of rm—it does exactly what you tell it to do, immediately, without asking if you’re sure.

To delete a folder and everything inside it:

Terminal window
rm -r restaurant-copy

The -r flag means “recursive” — delete this folder and everything it contains. Be very careful with this.

The most dangerous command in computing (DO NOT RUN THIS, just know it exists):

rm -rf / ← NEVER DO THIS. Deletes everything on the computer. Everything.

Rule of thumb: always double-check what you’re deleting before pressing Enter.


Command 9: clear — “Clean the Screen”

Section titled “Command 9: clear — “Clean the Screen””

After running many commands, your screen gets cluttered. clear wipes the screen so you start fresh.

Terminal window
clear

Your screen is now clean. Nothing was deleted — it just scrolled the old output out of view. You can still scroll up to see it.

Keyboard shortcut: On most terminals, Ctrl + L does the same thing.


Keep this handy until these become muscle memory:

CommandWhat It DoesKitchen Analogy
pwdShows where you are”What room am I in?”
lsLists what’s here”What’s on this shelf?”
cdMoves to another place”Walk to another room”
mkdirCreates a new folder”Build a new room”
touchCreates an empty file”Put a blank paper on the counter”
cpCopies a file”Photocopy this recipe”
mvMoves or renames”Move this to another shelf” or “relabel it”
rmDeletes permanently”Shred this paper” (NO recycle bin!)
clearCleans the screen”Wipe the whiteboard”

You might be wondering if professionals really use these basic commands every day. Absolutely. Here is how they look in the real world:

  • A DevOps engineer uses mkdir -p to instantly create identical deployment directory structures across 50 servers at once.
  • A Site Reliability Engineer (SRE) uses ls -lt | head during a major site outage to instantly find the most recently changed configuration file that might have caused the crash.
  • A Systems Administrator uses cd ~ and pwd constantly to re-orient themselves after jumping through dozens of different server environments.

Let’s be honest: the terminal isn’t the best tool for everything. You should absolutely reach for a graphical file manager (like Finder or Windows Explorer) when:

  • Bulk Visual Sorting: You need to visually browse and sort through hundreds of photos or design assets.
  • Drag-and-Drop Workflows: You are dragging files between different applications, like dropping an image into a web browser.
  • Quick Previews: You want to tap the spacebar to quickly preview a video or PDF without opening a full application.

Use the terminal when you need precision, automation, or remote access. Use the GUI when you need visual intuition. Professionals use both.


  • The terminal predates the mouse by decades. Computers used text-only interfaces from the 1960s until the mid-1980s. The graphical mouse-and-windows interface you’re used to was popularized by the Apple Macintosh in 1984. When you use a terminal, you’re using the original way humans talked to computers.

  • ls is one of the oldest commands still in use. It dates back to 1961 in MIT’s Compatible Time-Sharing System (CTSS), where it was called LISTF. The modern ls appeared in the first version of Unix in 1971. You’re using a command that’s over 50 years old.

  • The ~ (tilde) for home directory comes from a keyboard accident. On early terminals, the Home key and the ~ key were on the same physical key. The convention stuck, and now every terminal in the world uses ~ to mean “home.”


This is a bonus section — feel free to skim it now and come back later. You don’t need to master this today.

Sometimes you want to take the output of one command and feed it into another command. That’s what the pipe (|) does.

Kitchen analogy: Think of it like an assembly line. One station chops the vegetables, then passes them down the line to the next station that cooks them. Each station does one job and hands off the result.

The | character (usually found above the Enter/Return key, typed with Shift + Backslash) sends the output of the command on its left into the command on its right.

Show only the first 5 files:

Terminal window
ls | head -5

ls lists everything, but head -5 takes only the first 5 lines. Useful when a folder has hundreds of files.

Search for a word inside a file:

Terminal window
cat menu.txt | grep "pasta"

cat displays the file contents, and grep "pasta" filters to show only lines containing “pasta.” (You’ll use grep a LOT in your career.)

Find a past command you typed:

Terminal window
history | grep "mkdir"

history shows every command you’ve typed, and grep "mkdir" filters it down to only the ones that included “mkdir.” Very handy when you can’t remember the exact command you ran earlier.

You’ll get more practice with pipes as the curriculum continues. For now, just remember: | connects commands like stations on an assembly line.


MistakeWhy It’s a ProblemWhat to Do Instead
Using rm without checking firstFiles are permanently deleted — no undoRun ls first to see what you’re about to delete
Forgetting -r when copying/removing folderscp folder newname fails for directoriesUse cp -r folder newname or rm -r folder
Spaces in file namesmkdir my folder creates TWO folders: “my” and “folder”Use quotes: mkdir "my folder" or dashes: mkdir my-folder
Getting lost in the file systemYou forget where you are and make files in the wrong placeType pwd frequently. Use cd ~ to go home when lost
Typing commands wrong and getting frustratedTypos happen to everyone, every dayUse the up arrow key to recall your last command and fix it

  1. You ran mkdir projects but the folder appeared in a completely unexpected location. What command should you have run BEFORE mkdir, and why?

    Answer You should have run `pwd` first to check where you were. `mkdir` creates the folder in your current working directory, and if you navigated somewhere unexpected earlier without realizing it, the folder ends up in the wrong place. This is the #1 beginner mistake — always know where you are before creating or deleting anything. Run `pwd`, verify you're in the right place, then proceed.
  2. You need to reorganize your project folder. You want to keep your original logo file in the ‘assets’ folder but also need a version of it in the ‘public’ folder. Later, you realize a config file is in the wrong directory and needs to be relocated without leaving a duplicate behind. Which commands do you use for each task and why?

    Answer For the logo file, you use `cp` because you need a duplicate. `cp` (copy) creates a second identical file at the destination while leaving the original untouched, which is perfect for keeping your master asset safe. For the config file, you use `mv` because it needs to be relocated without leaving a messy duplicate behind. `mv` (move) removes the file from its original location and places it in the new one, keeping your directory structure clean.
  3. You are cleaning up old log files in your terminal and accidentally type rm production-db.sql instead of rm production.log. You immediately hit Ctrl+Z and look for the ‘Undo’ button or the Trash bin to recover your database backup. What happens next and why?

    Answer You will not be able to recover the database backup file. When you delete a file using `rm` in the terminal, it does not get moved to a temporary Trash or Recycle Bin like it does in a graphical interface. Instead, the file is permanently and immediately removed from the file system. There is no built-in undo feature or confirmation prompt by default, which is why you must always double-check your commands before pressing Enter.
  4. You are starting a new web project and need to create a deep directory structure app/frontend/components/buttons/ right away, but none of these folders exist yet. You try mkdir app/frontend/components/buttons/ but the terminal throws an error. What command should you use instead and why did the first one fail?

    Answer You should use `mkdir -p app/frontend/components/buttons/` to create the structure. The standard `mkdir` command fails in this scenario because it can only create a new folder if its parent directory already exists. By adding the `-p` (parents) flag, you instruct the command to automatically create any missing parent directories along the specified path. This saves you from having to run the command four separate times.
  5. You’ve been navigating through deep server logs for an hour and suddenly realize you have no idea which directory you are currently in, and you need to get back to your main user folder to run a script. What two commands do you use to figure out your location and return to your main folder, and why?

    Answer First, you use the `pwd` command to print your working directory, which tells you your exact current location in the file system so you can orient yourself. Then, you use the `cd ~` command to immediately jump back to your user's home directory. The tilde (`~`) symbol is a universal shortcut that always represents your home directory, regardless of how deep you are currently navigated. This combination quickly restores your context and puts you back in a safe, known location.

Hands-On Exercise: Build a Restaurant File Structure

Section titled “Hands-On Exercise: Build a Restaurant File Structure”

Let’s practice everything you’ve learned by creating a file structure for our imaginary restaurant.

Terminal window
cd ~
Terminal window
mkdir -p restaurant/kitchen/prep-area
mkdir -p restaurant/kitchen/cooking-stations
mkdir -p restaurant/dining-room
mkdir -p restaurant/storage/pantry
mkdir -p restaurant/storage/freezer
Terminal window
touch restaurant/kitchen/prep-area/chopping-board.txt
touch restaurant/kitchen/cooking-stations/grill.txt
touch restaurant/kitchen/cooking-stations/oven.txt
touch restaurant/dining-room/table-1.txt
touch restaurant/dining-room/table-2.txt
touch restaurant/storage/pantry/flour.txt
touch restaurant/storage/pantry/sugar.txt
touch restaurant/storage/freezer/ice-cream.txt
Terminal window
ls restaurant/
ls restaurant/kitchen/
ls restaurant/kitchen/cooking-stations/

Expected output for the last command:

grill.txt oven.txt

The ice cream is melting! Move it from the freezer to the prep area:

Terminal window
mv restaurant/storage/freezer/ice-cream.txt restaurant/kitchen/prep-area/

Verify:

Terminal window
ls restaurant/kitchen/prep-area/

Expected output:

chopping-board.txt ice-cream.txt
Terminal window
touch restaurant/menu.txt
cp restaurant/menu.txt restaurant/menu-backup.txt
ls restaurant/

When you’re done experimenting:

Terminal window
rm -r restaurant

Verify it’s gone:

Terminal window
ls | grep restaurant

No output means it’s gone.

Success criteria: You created a nested directory structure, created files inside it, moved files between directories, copied a file, and cleaned everything up. All without clicking a single button.


In Module 0.4: Files and Directories, you’ll dive deeper into how your computer organizes everything into files and folders, and how to navigate them like a pro.


You just used a tool that senior engineers use every day. You belong here.