skip to content

Command-line Environment

/ 3 min read

Table of Contents

Notes for The Missing Semester Lecture 2


1. Shell Globbing & Expansion

Wildcards and expansions help you select files or generate arguments efficiently.

  • * (Wildcard): Matches zero or more characters of any type.

  • Example: *.py matches all Python files.

  • ? (Single Character): Matches exactly one character of any type.

  • Example: file?.txt matches fileA.txt but not file10.txt.

  • {} (Brace Expansion): Expands a comma-separated list of patterns into multiple arguments.

  • Example: convert image.{png,jpg} expands to convert image.png image.jpg.

  • Example: touch foo{1,2,3} creates foo1, foo2, and foo3.


2. Quoting & Variables

Understanding how the shell interprets text is crucial for writing scripts.

  • Difference between ' ' and " ":

  • Single Quotes (' '): Preserves the literal value of each character. Variables are not expanded.

  • Double Quotes (" "): Preserves the literal value of most characters, but allows for variable expansion (interpreting $VAR) and escape characters.

  • Environment Variables (export):

  • Use export to modify the current environment.

  • Key concept: Variables set with export are inherited by all child processes (commands you run from that shell).


3. Streams & Redirection

Tools for manipulating input and output streams.

  • Process Substitution <( CMD ):

  • Executes CMD and places the output in a temporary file (via a named pipe), then substitutes <() with that file path.

  • Example: diff <(ls src) <(ls docs) compares the file lists of two directories without creating intermediate files.

  • FZF (Fuzzy Finder):

  • A command-line fuzzy finder. It reads lines from stdin and provides an interactive interface to filter and select items.


4. Process Management & Job Control

Managing programs that are executing simultaneously.

  • Signals:

  • SIGINT (Ctrl+C): Interrupts the process (requests it to stop).

  • SIGQUIT (Ctrl+): Quits the process (often produces a core dump).

  • SIGTERM: Terminate signal (polite kill request).

  • SIGSTOP (Ctrl+Z): Pauses a process.

  • Job Control Commands:

  • jobs: Lists unfinished jobs associated with the current terminal session.

  • fg: Brings a paused/background job to the foreground.

  • bg: Resumes a paused job in the background.

  • nohup: (No Hang Up) Runs a command immune to hangups, allowing it to keep running even if you close the terminal.


5. Remote Machines (SSH)

Securely connecting to and managing remote servers.

  • Key Generation:

  • ssh-keygen: Generates a public/private key pair.

  • Recommended command: ssh-keygen -a 100 -t ed25519 -f ~/.ssh/id_ed25519 (uses the modern Ed25519 algorithm).

  • Extract Public Key: ssh-keygen -y -f /path/to/private_key prints the public key derived from a private key.

  • Authentication:

  • Client side: You hold the private key.

  • Server side: Looks into ~/.ssh/authorized_keys to check if your public key is listed and allowed to connect.

  • Configuration:

  • ~/.ssh/config: Allows you to define aliases (e.g., ssh my-server) and default settings (user, port, identity file) for hosts.

  • File Transfer:

  • rsync: A tool for fast, versatile, remote (and local) file-copying. It only transfers differences between the source and destination.