Skip to content

Phase 3 · Free

3.1 Terminal, Shell, Prompt

The terminal is a window where you type instead of click. Clicking is fine until you need to do the same thing on fifty servers, or on a server that has no screen at all. Typing scales. Every lesson from here on is mostly typing.

Phase 3: Learn to Talk to Your Machine. Lesson 1 of 7. About 15 minutes.

Plain entry

The terminalThe window or screen where you type text commands and read their output, connected to a shell that runs those commands. Read more → is a window where you type instead of click. Clicking is fine until you need to do the same thing on fifty servers, or on a server that has no screen at all. Typing scales. Every lesson from here on is mostly typing.

Terms

  • Terminal: the window that shows text and takes your keystrokes.
  • Shell: the program inside the terminal that reads your command and runs it. Ubuntu’s is Bash.
  • Prompt: the text before your cursor, like you@bnlc-ubuntu:~$. It shows user, machine, and current folder. $ means normal user; # means root.
  • Command, argument, option: in ls -l /etc, ls is the command, -l is an option, /etc is an argument.
  • Root: the all-powerful admin account. You borrow its power with sudo.

Depth

whoami
echo $SHELL
echo "hello from $(hostname)"

Expected output:

yourname
/bin/bash
hello from bnlc-ubuntu

$SHELL is an environment variable. $(...) runs a command and drops its output in place.

Keys that save hours:

  • Tab completes names. Press twice to see options.
  • Up arrow recalls the last command. Ctrl+R searches history.
  • Ctrl+C stops the running command. Ctrl+L clears the screen.
  • history | tail shows your recent commands.

Reading help, the professional way:

man ls      # full manual, q to quit, /word to search
ls --help   # short summary

Going further

type ls shows whether a command is a program, an alias, or built into Bash. type cd reports cd is a shell builtin: it has to be, because a separate program cannot change your shell’s current folder.

Why it works this way

The shell reads your whole line, expands things like $SHELL and $(...), and only then runs the program. That is why echo "hello from $(hostname)" prints your machine name: echo never sees the $(...), it sees the result. Keep this in mind when a command does something odd. Ask what the shell turned your line into before blaming the program. type and echo let you check.

Self-check

  1. What is the difference between the terminal and the shell?
  2. What does # at the end of the prompt mean?
  3. How do you stop a command that is running forever?

Answers: (1) The terminal displays; the shell interprets. (2) You are root. (3) Ctrl+C.

Sources