Getting Started: Opening a Terminal and Choosing a Shell
Open a terminal on Linux, macOS or Windows, check which shell you are running, read the prompt and type your first commands.
Opening a terminal
Every system has a terminal built in.
- Linux: press
Ctrl + Alt + T, or search for "Terminal" in your applications. - macOS: open Spotlight with
Cmd + Space, type "Terminal" and press Enter. - Windows: the easiest option is WSL (Windows Subsystem for Linux). Open PowerShell as administrator, run
wsl --installand restart. You then get a real Linux terminal. Another option is to install Git Bash.
Once WSL is installed, everything in this course works the same as on a Linux machine.
Reading the prompt
When the terminal opens, the shell prints a prompt and waits for you to type. A common prompt looks like this:
alex@laptop:~$
Read it from left to right:
alexis your username.laptopis the name of the computer.~is the folder you are in right now. The tilde is a shortcut for your home folder, where your personal files live.$means the shell is ready for input and you are a normal user.
If the prompt ends with # instead, you are logged in as root, the administrator account. Root can change or delete anything on the system, so take extra care.
Your prompt may look slightly different. The exact text depends on your system, but it always ends with $ or #.
How to run a command
Type the command after the prompt and press Enter. The shell runs it, prints the output and shows a new prompt. If you press Enter on an empty line, nothing happens.
If you mistype a command, the shell tells you:
$ datee
bash: datee: command not found
This is harmless. Check your spelling and try again.
The parts of a command
Most commands follow this pattern:
command -options arguments
ls -l /home
- The command is the program to run, such as
ls. - Options change how the command behaves. They usually start with
-. Here-lasks for the long format. - Arguments say what the command should work on, such as a file or folder. Here
/homeis the folder to list.
Options and arguments are optional for many commands. Words are separated by spaces, and the order is always command first.
Your first commands
Type each of these and press Enter. None of them can damage your computer.
whoami
date
pwd
echo "Hello"
clear
whoamiprints your username.dateprints the current date and time.pwdprints the folder you are currently in. The name means "print working directory".echo "Hello"prints the text you give it. In this case it printsHello.clearclears the screen.
You can add a comment to any line by starting it with #. The shell ignores everything after the #. Comments are notes for people reading the commands.
pwd # this part is a comment
Which shell am I using?
The shell keeps some information about your session in named values called variables. One of them is SHELL, which holds the location of your shell program. You read a variable by putting a $ in front of its name, and echo prints it:
echo $SHELL
You will probably see /bin/bash or /bin/zsh. To see the version of Bash, run:
bash --version
On a Mac with zsh you can start Bash for this course by typing bash. Most commands behave the same either way. You will learn more about variables in a later lesson.
Two habits that save hours
- Tab completion: type the first letters of a command or file name and press
Tab. The shell completes the name for you. PressTabtwice to see all the options. This saves typing and prevents typos. - History: press the Up arrow to bring back previous commands. Press
Ctrl + Rand type a few letters to search through every command you have run before.
Keyboard shortcuts
Ctrl + C: stop the command that is running right now.Ctrl + L: clear the screen, the same asclear.Ctrl + AandCtrl + E: jump to the start and the end of the line you are typing.Ctrl + D: end input. On an empty prompt it closes the shell.
Ctrl + C before anything else. It is the standard way to stop a running command.Note that Ctrl + C in a terminal stops a command. It does not copy. To copy and paste in many terminals use Ctrl + Shift + C and Ctrl + Shift + V.
Getting help
Almost every command has a manual page:
man ls
ls --help
man ls opens the full manual for ls. Use the arrow keys to scroll and press q to quit. ls --help prints a shorter summary directly in the terminal. Manual pages are dense at first, but reading them is how people learn new options throughout their careers.