Meet the shell
The shell is a program that reads the commands you type and runs them. Ubuntu, Debian and Fedora use one called bash. It works in a loop: show a prompt, read a line, run it, then show the prompt again.
alex@lab:~$ is the prompt. It names the user (alex), the computer (lab) and the folder you are in. The ~ is short for your home folder, your own place on the disk. The $ means: ready.
Reading a line
We type cat *.txt and press Enter. cat is a program that prints what is inside files. The terminal hands the whole line to the shell, as plain text.
First the shell splits the line at the spaces into words: cat and *.txt. The first word is the command to run. The words after it are arguments: extra information for the command.
The * is a wildcard: it matches any run of characters. The shell reads the folder and swaps *.txt for every name ending in .txt, sorted A to Z: notes.txt and todo.txt. photo.jpg does not match.
Running it
cat is not built into the shell, so the shell searches the folders listed in a setting called PATH, left to right. /usr/local/bin has no cat; /usr/bin has one. The search stops at the first match.
The shell asks the kernel to start /usr/bin/cat with two system calls, fork and execve, and hands it the words: cat, notes.txt, todo.txt. Then the shell waits until cat has finished.
cat asks the kernel to open and read each file, then prints what is inside: buy milk from notes.txt, call mum from todo.txt. The text appears in the terminal.
cat ends and hands the shell a number called its exit status: 0 means success. The shell shows a new prompt and the loop starts again. Typing echo $? now would print that 0.
Some commands live inside the shell. type cd answers: cd is a shell builtin. cd changes the folder you are in, and a separate program cannot change the shell's folder, so the shell runs cd itself, with no search.
What happens
;; step 1/10 · what shell a program that reads commands and runs them bash the default shell on Ubuntu, Debian, Fedora its loop: 1 show a prompt 2 read a line 3 run it, wait for it to finish 4 back to 1
The prompt shown is the default shape on Ubuntu and Debian, for a user named alex on a computer named lab. Fedora's looks like [alex@lab ~]$. The shell builds it from a setting called PS1, and the root user (the administrator) sees # instead of $. The PATH on the card is shortened; a real one lists more folders (see yours with echo $PATH). On Ubuntu, Debian and Fedora, /bin is a link to /usr/bin, so cat is in both. bash also remembers where it found a command, so the next cat skips the search.