Have you ever ordered food by sending a chat message to a food stall you know? The chat app is only a window: the place where you type your message and read the reply. The cashier at the stall reads your message and understands what you want. The kitchen does the actual cooking.
You can also give a computer commands in text. You type one command and press Enter, and the operating system (the computer's basic program, such as Windows or Linux) runs it and answers in text too. The computer has the same three roles:
- The chat app is the terminal: the window you type in.
- The cashier is the shell: the program that reads your command.
- The kitchen is the operating system: it does the work.
Terminal, shell and CLI
People often use these three words as if they were the same, but they mean different things:
- The terminal (in full, terminal emulator) is the window app. Examples are GNOME Terminal on Ubuntu (a version of Linux), Terminal or iTerm2 on macOS, and Windows Terminal on Windows. Its only job is to show text and to pass what you type to the shell.
- The shell is the program inside the terminal window that reads your command, splits it into parts, then runs the program you asked for. The most common shells: bash (the default on most Linux systems) and zsh (the default on macOS since 2019). This course uses bash. On Windows you can get bash through WSL (a Windows feature that runs Linux).
- CLI (Command Line Interface) is the general name for using a computer by typing commands. Its opposite is the GUI (Graphical User Interface): a view that you use by clicking, such as File Explorer on Windows or Finder on macOS.
In daily talk, people say "open the terminal" for all three, and that is fine. But if someone asks about the difference: the terminal is the window, and the shell is the program that processes commands.
The prompt: the terminal is ready for a command
As soon as the terminal opens, the shell writes a prompt, a short text like the one below, then waits for you to type:
budi@laptop:~$
budiis the user name, andlaptopis the computer's name.~is the folder you are in right now.~is short for the home folder (a user's personal folder), here/home/budi.$means "ready, type here". In the default zsh on macOS, the prompt ends with%.
In all the examples in this course, the text after the prompt is what you type. The lines under it are the computer's answer.
Anatomy of a command
A command is made of parts separated by spaces. This command has three parts:
ls -a web-project
lsis the command: the part that says what to do.lsmeans "show what is in a folder".-ais a flag (also called an option): a part that changes how the command works.-ameans all: hidden files are shown too. Short flags start with-. Long flags start with--, for example--all. Several short flags can be combined:-l -ais the same as-la.web-projectis the argument: the thing the command works on, here the folder you want to look into.
Because spaces separate the parts of a command, a name that contains a space needs quotes: ls "school work".
Your first commands
This is the terminal on Budi's laptop, with the output (the answer) that bash really shows on Linux:
budi@laptop:~$ whoami
budi
budi@laptop:~$ pwd
/home/budi
budi@laptop:~$ ls
Documents Downloads web-project
budi@laptop:~$ ls web-project
error.log index.html logs script.js src style.css
budi@laptop:~$ ls -a web-project
. .. .env error.log index.html logs script.js src style.css
budi@laptop:~$ echo "Hello, Terminal"
Hello, Terminal
whoamishows the name of the user who is logged in.pwd(print working directory) shows the folder you are in, in full from the top folder (the root).lsshows what is in the folder you are in, or in a folder you name, such asweb-project. On Ubuntu, folder names are coloured blue.ls -a web-projectshows 3 extra names..envis a hidden file: plainlsdoes not show a file whose name starts with a dot..means the folder itself, and..means its parent folder.echoshows the text you give it.clear(or Ctrl+L) clears the screen. Your command history stays.
Who does the work for those commands? Take ls as the example. The shell splits the line you typed, looks for a program called ls in the folders where programs are stored, such as /usr/bin, and runs that program. Some commands, such as cd (change folder), pwd and echo, are builtins: the shell does them itself without calling another program.
If you use Windows, you have three choices for running these commands. This lesson uses bash, so the default choice is WSL:
| Option | When to pick it |
|---|---|
| WSL (Ubuntu) | The default for this lesson. WSL runs real Linux, so the commands are the same as on any Linux system. Install it by typing wsl --install in PowerShell (a shell that comes with Windows), opened as administrator. |
| Git Bash | Installed together with Git for Windows. Enough for basic commands like ls, cd and pwd, without installing Linux. |
| PowerShell | Already on Windows, but its commands are different from bash. In PowerShell, ls is another name for Get-ChildItem: the output looks different, and hidden files only appear with ls -Force, not ls -a. |
When you mistype a command
The shell treats upper and lower case letters as different. On Linux, LS is not ls, so the shell cannot find a program called LS:
budi@laptop:~$ LS
bash: LS: command not found
The shell wrote the command not found message, and every shell has its own style of message. If the same window runs zsh, the message becomes zsh: command not found: LS.
Compare that with an error that comes from a program, not from the shell. In this example, Budi asks for a folder that does not exist:
budi@laptop:~$ ls project
ls: cannot access 'project': No such file or directory
The program ls wrote this message, so it reads exactly the same in bash and in zsh. What can change the message is the version of the program ls. macOS has a different version of ls, so on a Mac the message is a little different: ls: project: No such file or directory. Read error messages slowly. They usually say three things: which program reports the problem (ls), what it was looking for ('project') and what the problem is (that folder does not exist).
Shortcuts you'll use right away
| Key | What it does |
|---|---|
Tab |
Completes the name of a command, file or folder you've typed part of |
↑ / ↓ |
Brings back earlier commands |
Ctrl+C |
Stops the command that's running (not copy) |
Ctrl+L |
Clears the screen, the same as clear |
Ctrl+Shift+C / Ctrl+Shift+V |
Copy and paste in a Linux terminal. On macOS it's still Cmd+C / Cmd+V |
💡 Why developers still use the terminal
- Servers have no screen. Your website will run on a server: another computer that stays on 24 hours a day. You manage that server from far away, through a terminal.
- Many developer tools only have a CLI. Git, npm and build tools (tools for building websites) are run by typing commands.
- It can be repeated. The same command gives the same result. You can copy a command for a friend, and you can save commands as a script (a file with a list of commands) that runs on its own.
⚠️ Four first-day mix-ups
- Treating the terminal and the shell as the same thing. The terminal is only the window that shows text. The shell reads and runs the command, for example bash, zsh or fish.
- Upper and lower case.
LSis notls, anddocumentsis notDocuments. On Linux, those are two different names. macOS usually treats them as the same name, but don't rely on that. - Spaces in file names.
ls school workis read as two arguments,schoolandwork. Use quotes:ls "school work". - Pasting commands you don't understand. Almost every command is safe. But a command from the internet that contains
sudo(run with admin rights) orrm -rf(delete a folder and everything in it) can change or delete a lot. Understand it first, then run it.
TL;DR: The terminal is the window for giving the computer commands in text. The shell (bash, zsh) is the program inside the terminal that reads and runs commands. CLI is the general name for working by typing commands, the opposite of a GUI (a view you click). A prompt such as budi@laptop:~$ means the shell is ready for a command. A command can have three parts separated by spaces: the command (what to do), flags (they change how it works, and start with -) and arguments (the things it works on). Start with whoami (your user name), pwd (the folder you are in), ls (what is in a folder), ls -a (hidden files too), echo (show text) and clear (clear the screen). On Linux, upper and lower case are different. The message command not found comes from the shell. Tab (complete a name), ↑ (the previous command) and Ctrl+C (stop a command) are the first shortcuts to learn.
⚡ The window and the command reader
Guess first: terminal or shell, which one reads your command?
The shell. The terminal is only the window: the place where you type commands and read the reply. The shell is the program inside that window that processes the command, for example bash or zsh.
Meaning: Compare it with ordering food by chat. The chat app is the terminal, and the cashier who understands your order is the shell. The kitchen that makes the order is the operating system (the computer's basic program, such as Windows or Linux).
⚡ The prompt: ready for a command
Meaning: A prompt is the text the shell writes when it is ready for a command, for example budi@laptop:~$. budi is the user name, laptop is the computer's name, ~ is the folder you are in (the home folder, your personal folder), and $ means "ready, type here".
⚡ Command, flag, argument
Write:
ls -a web-project
Meaning: ls is the command: what to do (show what is in a folder). -a is a flag: it changes how the command works (hidden files are shown too). web-project is the argument: the thing the command works on (the folder to look into). The parts are separated by spaces, so a name that contains a space needs quotes.
⚡ Your first commands
Write:
whoami
pwd
Meaning: whoami shows your user name. pwd shows the folder you are in right now. On Linux, upper and lower case are different: if you type LS instead of ls, the shell answers command not found.