Setting Up a Linux Environment and Getting Comfortable with the Shell
This article sets up the environment you'll practice in for the whole series, then gets you comfortable with the shell — where you type commands. By the end you'll be running your first commands and know a few shortcuts that make typing commands noticeably faster.
Setting up the Linux lab
As mentioned in Article 0, we use a container as our Linux to play with. Create an Ubuntu container and name it so you can reuse it:
docker run -it --name linuxlab ubuntu:24.04 bash
-itgives you an interactive terminal inside the container.--name linuxlabnames it so you can call it back later.bashis the program that runs when you enter — exactly the shell we'll learn.
You're now inside an Ubuntu. When you want to leave, type exit. The container stops (but isn't deleted). Next time, return to that same container (keeping the files you created):
docker start -ai linuxlab
The distinction:
docker runcreates a new container (you lose old data if you recreate it);docker start -ai linuxlabrestarts the exact old container. Throughout the series, usestart -aito return to the lab — don'trunagain, or you'll lose your exercise files.
What a shell is
A shell is the program that takes the commands you type, runs them, and returns the result. The default shell on most distros is bash (Bourne Again Shell). There are others like zsh, sh, but the basic skills are the same.
When you enter the lab, you see a prompt like:
root@6f5ae945498b:/#
└─┬─┘ └────┬─────┘ └┬┘
user hostname cwd (# = you are root; $ = regular user)
Reading the prompt is very useful: it tells you who you are (root), which machine you're on (the hostname — here the container id), and which directory you're in (/ = the root directory). The final character is # when you're root (full privileges) and $ when you're a regular user — remember this detail, it reminds you what privileges you have.
Your first commands
Try each command:
whoami # which user you are
hostname # machine name
pwd # current directory (print working directory)
ls / # list the contents of the root directory
date # system date and time
uname -a # Linux kernel info
Example output of whoami and uname -a:
root
Linux 6f5ae945498b 6.12... aarch64 GNU/Linux
ls / shows Linux's core directories:
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
Don't worry if you don't understand them yet — Article 2 explains each one. For now just know: this is the directory tree everything in Linux lives in.
Print text and environment variables with echo:
echo "Xin chao Linux"
echo "Home cua toi: $HOME"
Xin chao Linux
Home cua toi: /root
$HOME is an environment variable — the shell substitutes it with its value (the path to your home directory). We'll meet variables again often in Article 16 (scripting).
What a command is: builtin vs. program
A command can be a builtin (built into the shell) or a program (an executable file somewhere in the system). The type command tells you which:
type echo
type ls
echo is a shell builtin
ls is /usr/bin/ls
echo is a bash builtin; ls is a program at /usr/bin/ls. When you type ls, the shell finds that program via the PATH variable (the list of directories that hold commands) and runs it.
Finding help when you forget how to use something
Nobody remembers every option. Two ways to look things up right in the terminal:
man ls # the full manual for the ls command; press q to quit
ls --help # a quick summary of the options
man opens the manual page (use the arrow keys/Space to scroll, q to quit, /keyword to search). --help is shorter and faster. When you hit an unfamiliar command in the series, these two are always available.
If
manreports it's missing (minimal containers often strip it out), install it withapt-get update && apt-get install -y man-db(package management in Article 11).--helpis almost always there.
Shortcuts that make typing commands faster
This is the part that makes using the terminal less painful:
- Tab — autocomplete command/file names. Type
ls /etthen press Tab and the shell completes it tols /etc/. Press Tab twice to see the choices. This is the most-used key. - ↑ / ↓ — browse back through commands you've typed. No need to retype a long command.
- Ctrl + C — cancel the running command.
- Ctrl + L (or
clear) — clear the screen. - Ctrl + R — search the command history (type a few characters and it finds a matching old command).
Review the commands you've typed:
history
Get into the habit of using Tab and ↑ right now — it saves a lot of time and avoids typos.
🧹 Cleanup
At the end of each article I note how to clean up. For this series it's mostly just files in the lab, costing nothing significant. Keep the linuxlab container to use in later articles (type exit to leave; the container only stops, it isn't deleted).
When you've finished the whole series and want to remove the lab entirely:
docker rm -f linuxlab
docker rmi ubuntu:24.04
Wrap-up
You now have a Linux to play with (the linuxlab container, return with docker start -ai linuxlab), understand what a shell is and can read the prompt, can run your first commands (pwd, ls, whoami, echo), know how to look things up with man/--help, and have the Tab/↑/Ctrl+C/Ctrl+R shortcuts.
In ls / you saw the Linux directory tree. Article 2 explains that tree: what each core directory (/etc, /var, /usr, /proc...) is for, and why people say "in Linux, everything is a file."