1. What are Shell, Terminal and Bash? โ
What you will learn in this chapter:
- The difference between terminal, shell and bash โ three separate concepts
- Opening your first terminal session and entering a command
- The meaning of the prompt symbol
- Basic commands:
pwd,echo,whoami,dateโฑ Time: ~15 minutes ๐งช Exercises:
bashlings watchโ 5 interactive exercises ready (exercises/01_intro/)
When you start working with Linux or macOS, the first terms you will hear are terminal, shell and bash. Many people think they are the same thing, but in reality these are three separate concepts. Let's look at each one in detail.
1.1. What is a Terminal? โ
A terminal (or "terminal emulator") is a graphical window of a program that lets you enter text-based commands and see their output.
In other words, the terminal is the door (window), and the shell is the waiter who comes through that door.
Popular terminal programs:
| OS | Terminal programs |
|---|---|
| macOS | Terminal.app, iTerm2, Warp, Alacritty |
| Linux | GNOME Terminal, Konsole, xterm, kitty |
| Windows | Windows Terminal, WSL, Git Bash |
Note
The terminal is just a "container". Which shell runs inside it is a separate matter.
1.2. What is a Shell? โ
A shell is the interpreter program between the user and the operating system kernel. You type ls, the shell reads it, sends the kernel a request to "give me the list of files in this folder", and returns the result to you.
flowchart LR
A[Foydalanuvchi] -->|buyruq yozadi| B[Terminal]
B -->|matnni uzatadi| C[Shell]
C -->|tizim chaqiruvi| D[Kernel / OS]
D -->|natija| C
C --> B --> AThe most popular shell programs:
bashโ Bourne Again SHell (standard on Linux)zshโ Z Shell (default on macOS, very feature-rich)fishโ Friendly Interactive Shell (modern, with auto-suggest)shโ POSIX shell (the most minimal)dash,kshโ other variants
1.3. What is Bash? โ
Bash (Bourne Again SHell) is a shell written by Brian Fox in 1989 for the GNU project. It is an extended, enhanced version of the old sh (Bourne shell).
Today, Bash is:
- The default on most Linux distributions
- The most widely used for writing scripts
- Compatible with the POSIX standard
- Used in millions of servers and CI/CD pipelines
Which shell are you running?
To find out your current shell type:
echo $SHELL
# /bin/bash yoki /bin/zshOr to see the version:
bash --version
# GNU bash, version 5.2.15(1)-release ...1.4. Prompt โ the command line symbol โ
When you open the terminal, a certain symbol is waiting for you:
user@hostname:~$This is the prompt. Its parts:
| Part | Meaning |
|---|---|
user | The username |
hostname | The computer name |
~ | The current directory (~ โ the home directory) |
$ | A regular user (# if root) |
Caution
If you see # in the prompt, you are working as root (superuser). Every command must be entered very carefully!
1.5. Your first commands โ
Let's get acquainted with the basic commands:
# Hello, world
echo "Salom, Bash!"
# Current date and time
date
# Information about the system
uname -a
# Which user are you?
whoami
# Which folder are you in?
pwd
# Where does an existing command run from?
which lsSample output:
$ whoami
mac
$ pwd
/Users/mac
$ which ls
/bin/ls1.6. man โ your helper โ
Every Unix command has its own manual. You open it with the man (manual) command:
man ls
man grep
man bashInside the manual:
- Up / Down:
โ โorjk - Search:
/word-to-search, thenEnter - Quit:
q
A faster option
Some commands support the --help flag:
ls --help
grep --help1.7. Command history and auto-complete โ
Bash gives you two enormous features that speed up your work:
History โ
history # list of recent commands
!! # re-runs the last command
!123 # runs command number 123 from the history
Ctrl + R # search the history (incremental search)Tab completion โ
You don't have to type the full command or file name โ press the Tab key and Bash will complete it for you.
cd Doc<Tab> # โ cd Documents/
ls -l README<Tab> # โ ls -l README.md1.8. Common mistakes โ
A warning for beginners
- Pay attention to spaces. In Bash
x=5is correct, butx = 5is wrong (the space makes them separate arguments). - Never run
rm -rf /. This will erase the entire system. - Use
sudothoughtfully. It means "I know what I'm doing". - Commands are case-sensitive.
lsandLSare not the same.
1.9. Exercises โ
๐งช Bashlings โ interactive exercises
This chapter's 5 exercises come with auto-checking via the bashlings CLI:
bashlings watch # start from the first pending exercise
bashlings run intro1 # check a single exercise
bashlings hint intro1 # step-by-step hintSource: exercises/01_intro/
Do the following additional tasks by hand in the terminal:
- Print the full path of your home directory.
- Determine which shell you are using.
- View the
bashversion. - Open the
manpage of thedatecommand and find and apply the--iso-8601flag. - Print the last 5 commands from the history (
history | tail -5).
1.10. Summary โ
| Term | Essence |
|---|---|
| Terminal | A window with a text interface (a program) |
| Shell | An interpreter that understands commands (bash, zsh, fish) |
| Bash | The most popular shell program |
| Prompt | The command input line ($ or #) |
man | The command manual |
In the next chapter we will learn navigating the file system: cd, ls, pwd, mkdir, cp, mv, rm.
Next page: 2. Navigating the file system โ