Introduction to GNU/Linux and Bash Shell

GNU/Linux Operating System Architecture

  • Operating System (OS) Definition:

    • An Operating System is a collection of software that enables effective utilization and management of computer hardware.
  • Core Components of an Operating System:

    • Kernel:
    • Manages core activities of the operating system.
    • Linux: A free and open-source kernel, developed mostly using the C programming language.
    • GNU Foundation Software:
    • A collection of utility programs developed by the GNU foundation that interact with the kernel to perform various tasks for the user.
    • GNU software is far more important than the Linux kernel itself.
    • Even the Linux kernel is compiled using the GCC compiler provided by the GNU foundation.
  • GNU vs. Linux Terminology:

    • Stating "I am using Linux" is technically incorrect for most desktop and server systems.
    • Users are primarily using GNU tools running on top of the Linux kernel.
  • Operating System Support Capabilities:

    • Multi-user: Allows multiple users to access and use the same computer simultaneously and/or at different times.
    • Multiprocessing: Supports and utilizes more than one computer processor (CPU).
    • Multitasking: Allows multiple software processes to run concurrently at the same time.
  • Graphical Desktop & Distributions:

    • Provides a highly customizable graphical desktop environment similar to Windows or macOS.
    • Different Linux distributions (such as Ubuntu, Fedora, Mint, etc.) provide different Graphical User Interfaces (GUIs).

Bash Shell & Terminal Operations

  • Server Environment Standards:

    • Most server systems run GNU/Linux and typically do not use a graphical desktop interface.
    • Access and control are accomplished via the GNU bash shell.
  • Shell Definition & Functions:

    • A shell is a program that helps start up (or launch) other programs.
    • Operates inside a terminal window.
    • Bash (Bourne Again Shell) is a popular shell for GNU/Linux, providing a textual or command-line interface (CLI).
  • Terminal Interface Mechanics:

    • Commands are entered at the shell prompt, which is usually represented by the $ symbol.
    • Example prompt representation: cse278@vbox:~$
    • Output generated by executed programs is displayed directly inside the terminal.
    • The Bash shell can also be executed in integrated terminal environments, such as the VS-Code Terminal.
  • Fedora Virtual Machine (VM) Navigation:

    • In CSE-278, coursework utilizes a Fedora VM.
    • Launching a terminal in Fedora: Click the Activities button located at the top-left corner of the desktop screen.

Shell Command Structure & Syntax

  • Procedure to Execute Shell Commands:

    1. Type Command Name: Selected based on the specific operation to perform.
    2. Specify Options:
    • Modifies or tunes the behavior of the command.
    • Each command has distinct options, typically starting with a single dash - or double dashes --.
    • Option descriptions and effects can be researched via manual (man) pages.
    1. Supply Arguments:
    • Additional parameters such as file names, directory names, or path strings.
    1. Execute: Press the Enter key to run the command.
  • Annotated Command Syntax Example:

    • Full command string: $ g++ -g -Wall -std=c++17 hello.cpp
    • Detailed functional breakdown:
    • Command: g++ (GNU C++ compiler)
    • Options: -g (include debug symbols), -Wall (enable all compiler warnings), -std=c++17 (use C++17 standard)
    • Arguments: hello.cpp (source code file argument)

Fundamental Shell Commands Reference

  • Directory Technical Terminology:

    • "Directory" (dir) is the technical computer term for a graphical "folder".
  • Core Command Set:

    • pwd: Print Current Working Directory (CWD) / Show Present Working Directory (PWD).
    • ls <dir>: List files in the current working directory, or in directory <dir> if specified.
    • cd <dir>: Change current working directory to specified directory <dir>.
    • cp <file1> <file2>: Copy file or path <file1> to destination <file2>.
    • mv <file1> <file2>: Move (or rename) file or path <file1> to <file2>.
    • rm <file1>: Remove (delete) file <file1>.
    • clear: Clear all content from the active terminal screen.
    • mkdir <dir>: Create a new directory named <dir>.

Directory Structure, Files, and Path Navigation

  • Command Prompt Workflow Requirements:

    • Maintain continuous awareness of the Current Working Directory (CWD).
    • Construct an precise mental model of the overall directory hierarchy.
    • Formulate file path strings mentally prior to executing commands.
  • Sample Directory Tree Layout:

    • Base path: /home/harveysd
    • Structural layout:
    • /home/harveysd/
      • cse278/
      • exercise1/
      • homework1/
      • public_html/
      • hw2/
  • Directory Operations Example:

    • Context: CWD is set to cse278 (/home/harveysd/cse278).
    • Goal: Copy data.txt from exercise1 into the homework1 directory.
    • Equivalent Command Options:
    • Option 1: $ cp exercise1/data.txt homework1
    • Option 2: $ cp exercise1/data.txt homework1/data.txt
  • Relative Path Meta-Names:

    • ./ (dot-slash): Refers directly to the Current Working Directory (CWD).
    • ../ (dot-dot-slash): Refers to the parent directory of the current location.
    • ../../: Refers to the grandparent directory (no upper limit on chaining ../ sequences).
    • ~/ (tilde-slash): Refers to the user's home directory (operates as an absolute path representation).
  • Practical Relative Path Navigation Examples:

    • Initial state assumption: CWD is /home/harveysd/cse278.
    • Task 1: Copy file data.txt from exercise1 to public_html:
    • Command: $ cp exercise1/data.txt ../public_html
    • Task 2: Change CWD to hw2:
    • Command: $ cd ../public_html/hw2
    • Verification: Executing $ pwd returns /home/harveysd/public_html/hw2.

Terminal Productivity & Execution Control

  • Tab Completion:

    • Use the Tab key to automatically complete directory or file names.
    • Prevents spelling mistakes and avoids typing long directory or file paths manually.
  • Command History Navigation:

    • Press the Up and Down arrow keys to navigate and re-run previous commands in the shell history.
  • Interrupting Execution:

    • Press Control+C (Ctrl+C) simultaneously to interrupt or stop a process if a command is hanging or running indefinitely.
  • Mastery Practices:

    • Gaining fluency in Bash requires constructing an accurate mental model through regular practice.
    • Practice method: Create sample directories, write copy/move/delete command challenges, execute them in the terminal, and verify the resulting directory state.