Foundations Module 4 · Cheat Sheets

Linux Commands Reference

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

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

Most commands below are POSIX-style (Linux/macOS, or WSL/Git Bash on Windows). Windows-native alternatives are noted where needed. Some GNU flags may behave differently on macOS — for example, sed -i requires sed -i '' on macOS.

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 -
TRY ITYou've just opened your terminal and want to see which folder you're in. What command do you type?
$

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

TRY ITYou want to create a new folder called 'analysis' inside an existing folder called 'project'. What single command does this?
$

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"
TRY ITYou have a file called 'results.csv' and you want to quickly see what's inside it. What command prints its contents?
$
🧬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 / State 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 usernamewhoamiuser
which commandShow where a command liveswhich node/usr/bin/node
echo textPrint text to screenecho "hello"
dateShow current date/timedate
clearClear the terminal screenclear
historyShow command historyhistory
TRY ITYou just installed Node.js and want to confirm the terminal can find it. What command shows you where 'node' is installed?
$

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 packageAll (needs Python)
brew install <package>Install via HomebrewmacOS / Linux
sudo apt update && sudo apt install <package>Install via APTUbuntu / Debian
winget install <package>Install via Windows Package ManagerWindows

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)man grep
<command> --helpShow a brief usage summaryls --help
which <command>Show where a command is installedwhich 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 administratorsudo 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> or command -v <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 with npm 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

  • You only need about 10 commands for 90% of your work: pwd, ls, cd, mkdir, touch, cat, cp, mv, rm, and grep.
  • 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 line

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.