Foundations Module 5 · Cheat Sheets (Reference)

Terminal Commands Reference

Last reviewed

Beginner

What you'll learn

~10 min
  • Look up any common terminal command quickly
  • Navigate the filesystem, manage files, and search for content
  • Understand what a command does before running it
  • Use package managers to install CLI tools
  • Translate a command between Bash/Zsh and Windows PowerShell

By the end of this lesson, you will have a reliable reference for every terminal command you are likely to need during this course. You do not need to memorize any of this — the goal is to know where to look.

💡How to use this cheat sheet

Bookmark this page. You don’t need to memorize these commands — come back whenever you forget one. Use Ctrl+F (or Cmd+F on Mac) to search for what you need.

Mental model: the terminal is a filing cabinet

Think of your computer’s filesystem like a giant filing cabinet. Each drawer is a folder, each paper inside is a file. Terminal commands are just instructions like “open this drawer,” “move that paper,” or “find every paper with the word budget in it.” You already know how to do these things with a mouse — the terminal is simply a faster way to say the same thing out loud.

ℹPlatform note

The tables below use Bash/Zsh, the shells on macOS, Linux, WSL, and Codespaces. Windows PowerShell understands many of the same names, and the next table shows where it differs. Some GNU flags also behave differently on macOS: for example, sed -i needs sed -i '' there.

Bash/Zsh and Windows PowerShell side by side

These everyday commands work with the same name in both: pwd, ls, cd, mkdir, cat, cp, mv, rm, clear, echo, whoami, and history. The flags after the name are where they part ways.

Bash/Zsh vs PowerShell

Same task, two shells

TaskBash/Zsh (macOS, Linux, WSL)Windows PowerShell
Where am I?pwdpwd
List files, including hiddenls -lals -Force
Make nested foldersmkdir -p a/b/cmkdir a/b/c (creates the whole chain)
Create an empty filetouch notes.txtNew-Item notes.txt (there is no touch)
Copy or delete a foldercp -r src dest, rm -r oldcp -Recurse src dest, rm -Recurse old
First or last lines of a filehead log.txt, tail log.txtGet-Content log.txt -Head 10, Get-Content log.txt -Tail 10
Search inside filesgrep "error" log.txtSelect-String "error" log.txt
Find where a program liveswhich nodewhere.exe node (or Get-Command node)
Set a variable for this sessionexport NAME="val"$env:NAME="val"
Install softwarebrew install git (macOS), sudo apt install git (Ubuntu)winget install Git.Git
Run as administratorsudo commandRight-click the terminal, then Run as administrator
Get help on a commandman ls or ls --helpGet-Help ls
⚠Type where.exe, not where, in PowerShell

In PowerShell, plain where is a shortcut for a different command that filters lists, so it prints nothing useful. Include the .exe.

Moving around the filesystem.

Navigation

Moving around the filesystem

CommandWhat it doesExample
pwdPrint current directorypwd → /home/user
lsList directory contentsls
ls -laList all files (including hidden) with detailsls -la
cd folderChange into a directorycd projects
cd ..Go up one directorycd ..
cd ~Go to home directorycd ~
cd -Go to previous directorycd -

Files and folders

Creating, copying, moving, and deleting.

Files & Folders

Creating, copying, moving, deleting

CommandWhat it doesExample
mkdir nameCreate a directorymkdir my-project
mkdir -p a/b/cCreate nested directoriesmkdir -p src/components/ui
touch fileCreate an empty file (Bash/Zsh; PowerShell: New-Item file)touch index.html
cp src destCopy a filecp file.txt backup.txt
cp -r src destCopy a folder recursivelycp -r project project-backup
mv src destMove or renamemv old.txt new.txt
rm fileDelete a file (permanent!)rm temp.txt
rm -r folderDelete a folder recursivelyrm -r old-project
⚠rm is forever

Unlike dragging something to the Trash on your desktop, rm does not have an undo. There is no recycling bin. Double-check your command before pressing Enter, especially with rm -r.

Reading and searching

Viewing file contents and finding things.

Reading & Searching

Viewing file contents and finding things

CommandWhat it doesExample
cat filePrint file contentscat README.md
head fileShow first 10 lineshead log.txt
head -n 20 fileShow first 20 lineshead -n 20 log.txt
tail fileShow last 10 linestail server.log
tail -f fileFollow live updates (Ctrl+C to stop)tail -f server.log
less fileScroll through a file (q to quit)less long-file.txt
grep pattern fileSearch for text in a filegrep "error" log.txt
grep -r pattern dirSearch recursively in directorygrep -r "TODO" src/
find dir -name patternFind files by namefind . -name "*.js"
🧬In Your Field: Biotechclick to expand

Working with sequencing data or large CSV exports? Use head -5 results.csv to peek at just the first five lines. For FASTA files, grep -c '>' sequences.fasta counts how many sequences are in the file. These quick checks save you from opening a 2 GB file in Excel.

📊In Your Field: MIS / Businessclick to expand

Dealing with exported reports or database dumps? grep "2026-01" transactions.csv pulls out every line from January 2026. Combine it with wc -l to count matches: grep "2026-01" transactions.csv | wc -l tells you how many January transactions you have.

🏛️In Your Field: Government Devclick to expand

Government projects often involve searching through configuration files or logs. grep -r "API_KEY" . searches every file in the current directory for the text “API_KEY” — useful when you need to find where a setting lives across a complex project.

System info

Learning about your environment.

System Info

Learning about your environment

CommandWhat it doesExample
whoamiPrint your usernamewhoami → user
which commandShow where a command lives (PowerShell: where.exe command)which node → /home/user/.nvm/versions/node/v22.x.x/bin/node
echo textPrint text to screenecho "hello"
dateShow current date/timedate
clearClear the terminal screenclear
historyShow command historyhistory

Package managers

Installing software (you will need these for CLI tools).

Package Managers

Installing software (you'll need these for CLI tools)

CommandWhat it doesPlatform
npm install -g <package>Install a Node.js package globallyAll (needs Node.js)
npx <command>Run a package without installingAll (needs Node.js)
pip install <package>Install a Python package (on Ubuntu/WSL, inside a virtual environment: python3 -m venv .venv then source .venv/bin/activate)All (needs Python)
brew install <package>Install via HomebrewmacOS / Linux
sudo apt update, then sudo apt install <package>Install via APT (run as two separate commands)Ubuntu / Debian / WSL
winget install <package>Install via Windows Package ManagerWindows (PowerShell)

Getting help

When you forget how a command works, the terminal can help you.

Getting Help

How to look up command usage from the terminal

CommandWhat it doesExample
man <command>Open the manual page for a command (press q to quit; PowerShell: Get-Help)man grep
<command> --helpShow a brief usage summaryls --help
which <command>Show where a command is installed (PowerShell: where.exe)which node
command -v <command>Check if a command exists (portable alternative to which)command -v python3
💡Reading man pages

Man pages can look overwhelming at first. Focus on the SYNOPSIS (how to call the command) and DESCRIPTION (what it does). Scroll with arrow keys or Page Up/Down. Press / to search within the page, and q to quit.

Permissions and sudo

Running commands with elevated privileges.

Permissions & Sudo

Running commands with elevated privileges

CommandWhat it doesExample
sudo commandRun as administrator (Linux/macOS/WSL; it asks for your password, which stays invisible as you type)sudo apt install git
chmod +x fileMake a file executablechmod +x script.sh
chown user[:group] fileChange file ownershipchown user:group file

When things go wrong

Common problems and quick fixes:

ProblemQuick fix
Command is stuck / hangingPress Ctrl+C to interrupt
Stuck in a pager (: prompt)Press q to quit
command not foundCheck spelling, verify install with which <command> (PowerShell: where.exe <command>)
Wrong folderRun pwd then ls to orient yourself
Permission deniedCheck if you need sudo (for system commands) or if you’re in the wrong directory
Need help with a commandRun <command> --help or man <command>
🔧

When Things Go Wrong

Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.

Symptom
command not found
Evidence
bash: claude: command not found
What to ask the AI
"I installed Claude Code but the terminal says 'command not found.' How do I fix my PATH so the terminal can find it?"
Symptom
Permission denied
Evidence
Error: EACCES: permission denied, mkdir '/usr/local/lib'
What to ask the AI
"I got a permission error when running npm install -g. Should I use sudo, or is there a safer way to fix this?"
Symptom
No such file or directory
Evidence
cat: results.csv: No such file or directory
What to ask the AI
"The terminal says my file doesn't exist, but I know it's there. How do I check my current directory and find the file?"

Key takeaways

  • A handful of commands cover most daily work: pwd, ls, cd, mkdir, cat, cp, mv, rm, and grep (Select-String in PowerShell). Most of them share a name across Bash, Zsh, and PowerShell.
  • Bookmark this page rather than trying to memorize it. Even experienced developers look things up constantly.
  • When an AI tool suggests a command you don’t recognize, come back here to understand what it does before running it.
  • rm is permanent — always double-check before deleting.
🔍Going further with the command lineclick to expand

If you want to go deeper, look into these topics on your own time:

  • Piping (|): chain commands together, like cat file.txt | grep "error" | wc -l (count error lines)
  • Redirection (>, >>): send output to a file instead of the screen
  • Aliases: create shortcuts for long commands you use often
  • Shell scripts: save a sequence of commands in a .sh file and run them all at once

None of these are required for this course, but they can make your workflow even faster.

Search lessons