Shell, Terminal, Filesystem

Shell
  • A shell is a command interpreter

    • some are internal commands

    • most come from the Operating System (OS)

    • some are created by the user!

  • The shell is the interface between us, users, and the OS when it comes to using commands

    • So the name Command Line Interface (CLI)

The shell we will be using is bash, the Bourne Again Shell, an improvement over the original Shell called sh written by Stephen Bourne in 1977.

Shell, Terminal, Filesystem

Terminal Emulator
  • The shell interprets commands only

  • The job of the terminal is to get keystrokes (sometimes mouse events) from the user and display things

  • Nowadays, we don’t use terminals anymore, only terminal emulators

  • However, we commonly say terminal to designate both the terminal emulator and the shell!

Shell, Terminal, Filesystem

Filesystem
  • Everything within Linux is considered a file

  • Using the shell properly can’t be achieved without understanding the notion of Filesystem

  • Some slides about that later!

Command Prompt

  • Launching a terminal means creating a new shell process

  • Every shell has its own command prompt to invite us to type in commands (luisgustavo.nardin@fayol-nardin:~$ on the screenshot below)

linux terminal

For the sake of readability, the prompt will be written as the lighter $>

  • The command prompt is not to be entered by the user (you), it is already there!

  • No prompt means it is not possible to enter a command (chances are there is a command running in this shell already)

Anatomy of a command

A command
  • is a single program we want to run

  • can also be seen as a command pipeline

Each command may have
  • arguments (the raw materials it works on)

  • options (that alter its behaviour)

    • some options have arguments themselves…​

  • the command, its options and its arguments are separated by a word separator (space, tab or alike)

  • a command always issues a return code available via the ? variable

Anatomy of a command: an example

$> gcc -W -Wall -ansi -pendantic -o prog prog.c

  • $> : the command prompt (is not part of the command)

  • gcc : the command (possibly preceded by an absolute or relative path)

  • -W -Wall -ansi -pendantic -o prog : options

    • prog an argument for the option -o

  • prog.c : an argument for the command

$> gcc --version

  • --version is a long option

Anatomy of a command: guess 1/4

$> /usr/bin/ls

Anatomy of a command: guess 1/4

$> /usr/bin/ls

Anatomy of a command: guess 2/4

$> zip -r -9 -v homedir.zip ${HOME}

Anatomy of a command: guess 2/4

$> zip -r -9 -v homedir.zip ${HOME}

Anatomy of a command: guess 2/4

$> zip -r9v homedir.zip ${HOME}

Anatomy of a command: guess 3/4

$> LANG=C man -k who

Anatomy of a command: guess 3/4

$> LANG=C man -k who

Anatomy of a command: guess 4/4

$> tar zcvf homedir.tar.gz ${HOME}

Anatomy of a command: guess 4/4

$> tar zcvf homedir.tar.gz ${HOME}

Anatomy of a command: guess 4/4

$> tar -z -c -v -f homedir.tar.gz ${HOME}

Anatomy of a command: guess 4/4

$> tar --create --file homedir.tar.gz --verbose --gzip ${HOME}

Follow the PATH

  • Commands are present in various directories

  • To find a command, the Shell makes no guess, he only searches some directories
    ⇒ Those listed in the PATH variable

  • The Path is defined on a per user basis

Example of content for the PATH variable
$> echo ${PATH}
/home/luisgustavo.nardin/.local/bin:/home/luisgustavo.nardin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:.
Windows too has the notion of path. It is called …​ path and can be set using the GUI or the command line (cmd.exe or PowerShell)

References

‡ : read thoses pages on your own operating system, not on the Internet!