user spacealex@lab:~$ cat *.txtbuy milkcall mumalex@lab:~$ type cdcd is a shell builtinshell · bashword 1word 2word 3catLinux kerneldisk~ home foldernotes.txtphoto.jpgtodo.txt/usr/local/bincat/usr/bin/bincat *.txttype cdcat*.txtcat?0
Back: user space (terminal, shell, word cells, cat). Middle: the Linux kernel. Front: the diskOn the disk: the home folder (~) and the PATH foldersTokens: your typed line, its words, a PATH search, a start signal, file reads and the exit statusUser space at the back: the terminal, the shell (bash), three word cells and the cat program. The Linux kernel in the middle. The disk in front: the home folder and the PATH folders. Type cat *.txt: the shell splits it into words, swaps *.txt for the matching names, searches PATH for cat, starts it through the kernel, and shows a new prompt when cat hands back exit status 0. type cd is answered by the shell itself. 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.

Meet the shell

  1. 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.

Reading a line

Running it

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.