⏱ Estimated Time: 8-10 hours
Every developer uses the command line. Every single one.
The command line, often referred to as the "terminal," "shell," or "CLI" (Command Line Interface), is your backstage pass to interacting with your computer in a way that goes beyond clicking and dragging. When you're deploying code, managing servers, running build tools, or using Git — you're in the terminal. Most tutorials assume you already know your way around. We're going to make sure you do.
By the end of this module, the command line will feel like home.
The terminal (also called command line, shell, or console) is a text-based interface to your computer. Instead of clicking icons and menus, you type commands.
Why would anyone choose typing over clicking?
- Speed — Once you know the commands, you can do things in seconds that would take minutes with a mouse
- Power — Some tasks can only be done from the terminal
- Automation — You can write scripts to do repetitive tasks for you
- Remote access — When you're working on servers, the terminal is often your only option
Quick clarification:
- Terminal — The application/window you type in
- Shell — The program that interprets your commands
Common shells:
- Bash — The classic, available everywhere
- Zsh — Modern, powerful, default on Mac
- PowerShell — Windows (we recommend using Git Bash or WSL instead)
If you're on Mac, you're using Zsh by default. If you're on Linux, probably Bash. Either works fine for this course.
Mac:
- Press
Cmd + Space, type "Terminal", hit Enter - Or navigate to
Applications>Utilities>Terminal
Windows:
- Install Git for Windows which includes Git Bash
- Or use Windows Subsystem for Linux (WSL)
- Alternatively: Click
Start, thenAll Programs>Accessories>Command Prompt
Linux:
- Press
Ctrl + Alt + T - Or find Terminal in your applications menu
When you open the terminal, you'll see something like this:
username@computer:~$
Or on Mac with Zsh:
username@computer ~ %
This is your prompt. It's waiting for you to type a command.
The ~ represents your home directory. The $ or % indicates you're a regular user (not root/admin).
pwdpwd stands for "print working directory." It tells you where you are in the file system.
Output:
/Users/username
Windows alternative:
cdMac/Linux:
lsWindows:
dirls (or dir on Windows) lists the contents of the current directory.
Desktop Documents Downloads Pictures
ls -lThe -l flag shows a "long" listing with more information:
drwxr-xr-x 5 username staff 160 Jan 15 10:30 Desktop
drwxr-xr-x 8 username staff 256 Jan 14 09:15 Documents
This shows permissions, owner, size, date modified, and name.
See Hidden Files
ls -aFiles starting with . are hidden by default. The -a flag shows all files.
. .. .zshrc .gitconfig Desktop Documents
ls -laShows all files with details. You'll use this constantly.
cd Documentscd means "change directory." Now you're inside Documents.
pwd/Users/username/Documents
cd .... means "parent directory" — one level up.
cd ~Or just:
cdBoth take you to your home directory.
Absolute path — starts from root (/):
cd /Users/username/Documents/ProjectsRelative path — starts from where you are:
cd Documents/ProjectsIf you're already in /Users/username, both commands take you to the same place.
cd -Takes you to the previous directory you were in. Great for bouncing between two locations.
cd ~/Documents/ProjectsThe ~ expands to your home directory, so this works from anywhere.
Create a new directory called "VetsWhoCode":
mkdir VetsWhoCodeCreates a directory called VetsWhoCode.
Create nested directories:
mkdir -p projects/vwc/preworkThe -p flag creates parent directories as needed. This creates the entire nested structure in one command.
touch index.htmlCreates an empty file called index.html. If the file exists, it updates the timestamp.
touch index.html style.css script.jsCreates all three files at once.
cat README.mdcat prints the entire file to the terminal. Good for short files.
less README.mdless lets you scroll through longer files. Press q to quit.
head -20 README.mdShows the first 20 lines.
tail -20 README.mdShows the last 20 lines.
cp index.html backup.htmlCopies index.html to a new file called backup.html.
cp -r projects projects-backupThe -r flag copies directories recursively (including all contents).
mv old-name.html new-name.htmlRenames a file.
mv index.html ../Moves index.html to the parent directory.
mv index.html ~/Documents/Moves it to Documents.
Mac/Linux:
rm unwanted-file.txtDeletes the file. There is no trash. It's gone.
rm -r unwanted-folderor
rm -r NameOfDirectoryDeletes a directory and everything inside it.
Windows:
rmdir /S NameOfDirectory
⚠️ Be careful withrm. There's no undo. Double-check before you hit Enter, especially with-r.
Before deleting, list what you're about to remove:
ls unwanted-folderThen delete:
rm -r unwanted-folderfind . -name "*.html"Finds all .html files starting from the current directory (.).
find ~/Documents -name "index.html"Finds files named index.html in Documents.
grep "function" script.jsFinds lines containing "function" in script.js.
grep -r "TODO" .Recursively searches all files in the current directory for "TODO".
grep -n "error" logfile.txtThe -n flag shows line numbers.
This is where the terminal gets powerful.
The pipe | takes the output of one command and feeds it to another.
ls -la | lessLists files and sends the output to less so you can scroll through it.
cat logfile.txt | grep "error"Shows only lines containing "error".
history | grep "git"Shows your command history filtered to only git commands.
cat data.txt | grep "active" | wc -lThis:
- Reads the file
- Filters to lines with "active"
- Counts the lines (
wc -l)
ls -la > filelist.txtThe > redirects output to a file. Creates or overwrites the file.
echo "New line" >> notes.txtThe >> appends to a file instead of overwriting.
cat file1.txt file2.txt > combined.txtCombines two files into one.
historyShows your recent commands.
Press Up Arrow to cycle through previous commands.
Press Ctrl + R to search your history. Start typing and it finds matching commands.
| Shortcut | Action |
|---|---|
Ctrl + A |
Jump to beginning of line |
Ctrl + E |
Jump to end of line |
Ctrl + U |
Clear line before cursor |
Ctrl + K |
Clear line after cursor |
Ctrl + W |
Delete word before cursor |
Ctrl + L |
Clear the screen |
Ctrl + C |
Cancel current command |
Tab |
Auto-complete files and commands |
Tab completion is your best friend. Start typing a file or command name and press Tab. If there's one match, it completes. If there are multiple, press Tab twice to see options.
Your shell reads a config file when it starts:
- Zsh:
~/.zshrc - Bash:
~/.bashrcor~/.bash_profile
Aliases are shortcuts for commands you use often. Add these to your config file:
# Open the config file
nano ~/.zshrc # or ~/.bashrc for BashAdd aliases like:
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias home="cd ~"
alias projects="cd ~/Documents/projects"
# List files
alias ll="ls -la"
alias la="ls -a"
# Git shortcuts (preview - more in Git module)
alias gs="git status"
alias ga="git add"
alias gc="git commit"
alias gp="git push"
# Safety nets
alias rm="rm -i" # Asks for confirmation
alias mv="mv -i" # Asks before overwriting
alias cp="cp -i" # Asks before overwriting
# Clear screen
alias c="clear"Save the file and reload:
source ~/.zshrc # or source ~/.bashrcNow ll works as ls -la, gs works as git status, etc.
Add this to your config file:
export EDITOR="code" # VS CodeNow when programs need to open an editor, they'll use VS Code.
You can customize what your prompt displays. Here's a simple example:
# Shows: directory-name $
PS1="%1d $ "Or with colors:
# Shows: directory-name in blue, then $
PS1="%F{blue}%1d%f $ "Without looking at notes, complete these tasks:
- Open your terminal
- Print your current directory
- Navigate to your Documents folder
- List all files including hidden ones
- Go back to your home directory using the shortcut
- Navigate to Documents using an absolute path
- Create a directory called
vwc-prework - Inside it, create three directories:
html,css,js - Inside
html, create files:index.html,about.html,contact.html - Copy
index.htmlto the parentvwc-preworkdirectory - Rename the copy to
home.html - Delete
home.html - List the entire structure to verify
- Find all
.htmlfiles in yourvwc-preworkdirectory - Create a file with some text:
echo "Hello World" > greeting.txt - Use
grepto find "World" in that file - Use
catto display the file contents
- List all files in your home directory and count them:
ls ~ | wc -l - View your command history and filter to only
cdcommands - List files and save the output to a file called
my-files.txt
- Open your shell config file (
~/.zshrcor~/.bashrc) - Add at least 5 aliases that will help your workflow
- Save and reload the config
- Test each alias
You mistyped the command or it's not installed.
# Wrong
lss -la
# Right
ls -laThe file or path doesn't exist. Check your spelling and current location with pwd.
You don't have access. For your own files, this usually means the file isn't executable. For system files, you may need sudo (use carefully).
If a command is running and won't stop, press Ctrl + C to cancel it.
If your terminal looks weird (no prompt, strange characters), type:
resetThis restores it to normal.
You should be able to do all of the following from memory, without looking anything up:
- Navigate to any directory using both relative and absolute paths
- Create nested directory structures in one command
- Create, copy, move, and delete files and directories
- View file contents using multiple methods
- Find files by name
- Search for text inside files
- Use pipes to chain commands
- Redirect output to files
- Use keyboard shortcuts for efficiency
- Set up useful aliases in your shell config
Take a screenshot of your terminal showing:
- Your custom aliases (run
aliasto list them) - Your shell config file open, showing your customizations
This screenshot goes on your portfolio's About page.
| Command | Description |
|---|---|
pwd |
Print working directory |
ls / dir |
List files (Mac/Linux / Windows) |
ls -la |
List all files with details |
cd directory |
Change directory |
cd .. |
Go up one level |
cd ~ / cd |
Go to home |
cd - |
Go to previous directory |
| Command | Description |
|---|---|
mkdir name |
Create directory |
mkdir -p path/to/dir |
Create nested directories |
touch file |
Create file |
cp source dest |
Copy file |
cp -r source dest |
Copy directory |
mv source dest |
Move or rename |
rm file |
Delete file |
rm -r directory / rmdir /S |
Delete directory (Mac/Linux / Windows) |
| Command | Description |
|---|---|
cat file |
Print entire file |
less file |
Scroll through file |
head -n file |
First n lines |
tail -n file |
Last n lines |
| Command | Description |
|---|---|
find . -name "pattern" |
Find files by name |
grep "text" file |
Search in file |
grep -r "text" . |
Search recursively |
| Symbol | Description |
|---|---|
| |
Pipe output to next command |
> |
Redirect output to file (overwrite) |
>> |
Redirect output to file (append) |
Now, you're armed with the knowledge and tools to embark on your web development journey. Get ready to create, innovate, and make your mark on the digital world! 🚀
Next up: Module 2: Code Editor Setup