Terminal and Shell
Have you ever wondered about the difference between a terminal and a shell? While they are closely related and often used interchangeably, they actually refer to different components of the command-line interface experience.
-
Terminal (or terminal emulator): A terminal is an application that provides a text-based interface for interacting with the computer. Historically, "terminals" were physical devices (keyboard + display) that connected to a computer. Today, a terminal emulator is a program (like the Linux Terminal program, iTerm2, or Windows Terminal) that emulates this behavior in a window. The terminal provides input and output — it shows text and sends keystrokes to the running program.
-
Shell: A shell is a command-line interpreter program that runs inside the terminal. The shell reads commands you type, interprets them, and runs programs. Common shells include bash, zsh, fish, and PowerShell. The shell provides features like command history, tab completion, scripting, and job control.
In short: the terminal is the window/application; the shell is the program running inside that window which interprets your commands.
Set up a terminal
Depending on your operating system, the terminal may vary:
- On macOS, the built-in Terminal app works fine, but many people prefer iterm2.com
- On Windows, the recommended terminal program is Windows Terminal
- You may also need to enable the "OpenSSH Client" optional feature. See Microsoft's documentation for details.
- On Linux, a built-in terminal emulator provided by your desktop environment (gnome-terminal, konsole, xterm, etc.) can be used. The terminator terminal emulator is an excellent choice. It can be installed with
sudo apt install terminator.
Why it matters for SSH and tooling
- SSH is a protocol and client program that connects your local terminal to a remote shell on another machine. When you run
ssh orin03, your terminal is connected over the network to a shell session on that remote host. - Some features (like agent forwarding or interactive editors) depend on both the terminal emulator and the shell configuration working together, so it's useful to know which shell you're using when following guides.
Using a unix compatible shell
Open a terminal window to access your shell. You can run commands by typing them and pressing Enter.
Note: On Windows, the default shell is PowerShell, which has some differences from Unix-like shells (bash, zsh). For consistency with most documentation and tooling, it's recommended to use a Unix-compatible shell via the Windows Subsystem for Linux (WSL).
The state of your shell
Similar to your file explorer, your shell always has a "current working directory" (cwd). This is the folder that your shell is currently "in". You can see the current working directory by running. All of your commands will be run relative to this directory.
pwd
You can change the current working directory using the cd command:
cd path/to/folder
Types of paths
Folders are specified using paths. A path is a string that describes the location of a file or folder in the filesystem. Paths can be absolute (starting from the root path, which is the starting point of the entire file system /) or relative (starting from the current working directory).
There are a few special symbols used in paths:
- / : The root directory of the filesystem.
- . : The current directory.
- .. : The parent directory (one level up).
- ~ : The home directory of the current user (which is equivalent to the $HOME environment variable).
Environment variables
Environment variables are key-value pairs that can affect the behavior of processes on your system. They are often used to configure settings for applications and tools.
You can view all environment variables by running:
env
You can set an environment variable for the current shell session using the export command:
export VARIABLE_NAME="value"
You can use the variable in commands by prefixing it with a $:
echo $VARIABLE_NAME
Writing scripts
You can write shell scripts to automate tasks. A shell script is a text file containing a series of commands that the shell can execute.
- Create a new file with a
.shextension, e.g.,myscript.sh. - Add the shebang line at the top to specify the shell interpreter:
#!/bin/bash
chmod +x myscript.sh
./myscript.sh
Scripts are a powerful way to automate repetitive tasks and can be as simple or complex as needed. Common programming paradigms like variables, conditionals, and loops can all be used in shell scripts.
Aliases
Aliases are shortcuts for longer commands. You can create an alias to simplify frequently used commands. For example, instead of typing git status every time, you can create an alias:
alias gs='git status'
Now, you can just type gs to run git status instead of typing out the full command.