Skip to content

03. Terminal & Shell

While graphical interfaces (GUIs) exist in Linux, the true power, speed, and automation capabilities lie in the command line interface (CLI).

Often used interchangeably, there is a technical difference between a terminal, a console, and a TTY.

  • Terminal: Originally a physical hardware device (a screen and keyboard) used to interact with a mainframe. Today, it refers to software (a “Terminal Emulator” like GNOME Terminal, iTerm2, or Windows Terminal) that provides a text-based window to interact with the shell.
  • Console: The physical terminal directly connected to the host machine (e.g., the monitor and keyboard plugged into the server rack).
  • TTY (Teletypewriter): The subsystem in Linux that handles text input and output. When you log in locally, you get a TTY (usually TTY1 through TTY6).
  • Pseudo-terminal (PTY): When you SSH into a server or open a terminal emulator window, you aren’t using physical hardware. The OS creates a virtual TTY, known as a pty or pts (Pseudo-Terminal Slave), to handle the connection.

If the terminal is the window you type into, the Shell is the program running inside that window that interprets your commands and executes them.

  • Terminal: The graphical window you open.
  • Shell: The engine processing your commands (Bash, Zsh).
  • Bash (Bourne Again Shell): The default shell on almost all Linux distributions. Highly compatible and ubiquitous.
  • Zsh (Z Shell): Highly customizable and interactive. The default shell on macOS. Supports advanced auto-completion and themes (e.g., Oh My Zsh).
  • Fish (Friendly Interactive Shell): Known for syntax highlighting and intelligent auto-suggestion out of the box, but not strictly POSIX-compliant (some bash scripts won’t run natively in fish).

A typical shell command follows this structure:

Terminal window
command -options argument
  • Command: The program to run (e.g., ls).
  • Options (Flags): Modifies the behavior of the command, usually starting with a - (e.g., -l for long format, -a for all files).
  • Arguments: The target of the command (e.g., a file or directory name like /var/log).

Example: ls -la /var/log

  • Absolute Paths: The full path starting from the root directory (/).
    • Example: cd /etc/ssh
  • Relative Paths: The path starting from your current working directory.
    • Example: If you are in /etc, typing cd ssh takes you to /etc/ssh.
    • . means current directory.
    • .. means one directory up (parent directory).
  • Tab Completion: The most important shortcut in Linux. Start typing a file, directory, or command name, and press Tab. The shell will automatically complete it.
  • History: The shell remembers your past commands.
    • Type history to view them.
    • Use the Up and Down arrow keys to cycle through previous commands.
    • Press Ctrl + R to reverse search your history.
  • Aliases: Custom shortcuts for longer commands.
    Terminal window
    # Create a temporary alias
    alias ll='ls -la'
    # To make it permanent, add it to your ~/.bashrc or ~/.zshrc

You do not need to memorize every command and flag. Linux has built-in manuals.

  • man (Manual Pages): The most comprehensive help system.

    Terminal window
    man ls

    (Press q to quit the manual).

  • help: Used for shell built-in commands (like cd or alias) that don’t have separate man pages.

    Terminal window
    help cd
  • --help Flag: Most commands support this flag for a quick summary of options without opening the full manual pager.

    Terminal window
    mkdir --help
  • info: A different format of documentation, often containing hyperlinked nodes. Sometimes more detailed than man for GNU utilities.

    Terminal window
    info coreutils
  • whatis: Displays a brief, one-line description of a command.

    Terminal window
    whatis grep
  • apropos: Searches the manual page names and descriptions for a specific keyword. Perfect when you know what you want to do, but forgot the command name.

    Terminal window
    apropos "list directory"