01 - Setup¶
What this session is¶
About 30 minutes. You'll get a working Linux environment, open a terminal, and run your first commands.
Step 1: Get a Linux environment¶
Pick one based on your machine:
macOS¶
You already have a Unix shell. Open the Terminal app (search via Spotlight: ⌘ Space, type "terminal"). Done.
macOS isn't strictly Linux but it's close enough for everything in this path. ~95% of commands work identically.
Linux (native, dual-boot, or VM)¶
You're using Linux. Open a terminal. (Most desktop environments: Ctrl+Alt+T, or find "Terminal" in apps.)
If you don't have Linux yet and want to install it: - Ubuntu is the gentlest entry. ubuntu.com/download/desktop. Install in a VM (VirtualBox) if you don't want to dual-boot.
Windows: install WSL2¶
WSL2 (Windows Subsystem for Linux) runs a real Linux kernel inside Windows. Free, supported by Microsoft, the right way to learn Linux on a Windows machine.
Open PowerShell as Administrator and run:
That installs WSL2 and Ubuntu by default. Reboot if asked. Open the new "Ubuntu" app from your Start menu. The first launch sets up a username and password.
You now have a Linux terminal on Windows. Everything in this path works there.
Step 2: Your first command¶
In the terminal, type:
Press Enter. You should see:
That's a Linux command. echo is "print this." You just used the terminal.
Step 3: A few more essentials¶
Try these one at a time. After each, look at the output.
Prints your username.
Prints your machine's name.
"Print working directory." Shows the folder you're currently in. Probably /home/yourname or /Users/yourname.
"List." Shows the files and folders in the current directory.
The current date and time.
System info - kernel name, version, architecture.
Each of these is a separate command - a small program. The terminal lets you run them one after another.
What just happened¶
The terminal is a shell - a program that reads what you type, runs a corresponding command, and prints the result. The default shell on most Linux distributions is bash; on modern macOS it's zsh. They're 95% compatible for what we'll do.
When you typed echo "hello, world":
- echo is a command (a small program).
- "hello, world" is an argument (the input).
- The shell ran echo with that argument.
- echo printed its argument; the shell printed the output to your terminal.
The general shape: command argument1 argument2 ....
Try changing things¶
-
Run
echo hello(no quotes). Same output? (Usually - quotes are needed when the argument contains spaces or special characters.) -
Run
ls -l. What's different? (Long listing - shows more info per file.) -
Run
ls -a. (Includes "hidden" files - those starting with.) -
Run
ls -la. (Both options combined.) -
Run
ls /etc. (List the/etcfolder specifically.)
You've now seen options (also called flags): the things starting with - that modify a command's behavior.
A note on errors¶
Try this:
You'll see:
That's an error. The shell looked for a command called lz, didn't find one, told you. Errors aren't scary; they're feedback.
Try this:
You'll see something like:
Another error. Again, just feedback.
Reading errors is most of the skill. They almost always tell you exactly what's wrong.
Command history¶
Press the up arrow in your terminal. Your previous command appears. Press up again for the one before. This is history - the terminal remembers what you've typed.
Press Ctrl-R to search history: type a few characters and the shell finds matching past commands.
history (the command) prints a numbered list. !42 re-runs command #42. !! re-runs the last command.
You'll use history constantly.
Tab completion¶
Type:
Then press Tab. The shell completes it to cd /etc/ (the only thing starting with /e). Try cd /us then Tab - completes to /usr/.
If multiple things match, press Tab twice to see them all.
Tab completion is the single biggest productivity feature of the shell. Use it. Always.
Clearing the screen¶
Lots of output? Type clear or press Ctrl-L. Fresh screen.
Exiting the terminal¶
exit (the command). Or close the terminal window. Or Ctrl-D on an empty line.
Exercise¶
In your terminal, run each of these. Look at the output. Note anything that confuses you.
Try at least one wrong command (whodoami, say) and one with a wrong argument (cat nofile). Read the errors.
What you might wonder¶
"Why is ls not list?"
Old Unix tradition. Commands are short to type. Two-letter names for the most-used. Three- or four-letter for the next tier. Full words for less-used. You get used to it.
"What's the difference between bash and zsh?" Same shape. zsh has extras (better completion, better prompts, more configurability). For our purposes, identical.
"Do I need to type these commands every time?" You'll learn shortcuts. Up arrow for last command, Tab to complete, Ctrl-R to search history. Eventually you re-type very little.
"Should I be worried about typing dangerous commands?"
We'll be careful. The two dangerous commands to be conscious of:
- rm -rf (recursive delete, no confirmation) - we'll cover safely in page 03.
- Anything starting with sudo (page 06) - runs as the system admin user.
For now you can't break anything serious.
Done¶
You have: - A working Linux/macOS/WSL terminal. - Run your first commands. - Met options (flags) and history. - Used Tab completion.
Next page: navigate the filesystem.
Next: The shell - ls, cd, pwd →