---
tags:
- linux
- l1
- flashcard-deck
- terminal
---
<!-- wiki:breadcrumb:start -->
[Portal](../../../../library/portal/index.md) | **Level:** [L1: Foundations](../../../../library/portal/levels.md) | **Topics:** [Terminal Internals](../../../../library/portal/topics.md) | **Domain:** Linux
<!-- wiki:breadcrumb:end -->

id	category	difficulty	tags	question	answer	source_path
terminal/a1b2c3d4e5f6	terminal	easy	terminal,emulator,basics	What does a terminal emulator do?	It converts user input (keystrokes, mouse events) into bytes sent to programs, and renders output bytes as text, colors, and cursor movement on screen.\n\nRemember: "Terminal emulator = keyboard/screen translator." It doesn't run commands — the shell does. The terminal is just the I/O interface.\n\nExample: iTerm2, GNOME Terminal, Windows Terminal, Alacritty are all terminal emulators.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/b2c3d4e5f6a7	terminal	easy	terminal,shell,basics	What does the shell do?	It parses commands, expands globs and variables, sets up redirects and pipes, manages jobs, and launches programs.\n\nRemember: "Shell = command interpreter." bash, zsh, fish are shells. They run inside a terminal emulator.\n\nGotcha: Changing your terminal emulator doesn't change your shell, and vice versa.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/c3d4e5f6a7b8	terminal	easy	terminal,path,environment	What does the PATH environment variable control?	It specifies the directories the shell searches, in order, to find executable programs when you type a command.\n\nRemember: "PATH is searched left to right." First match wins. Prepend to override system commands, append to add new ones.\n\nExample: export PATH="$HOME/bin:$PATH" makes ~/bin commands take priority.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/d4e5f6a7b8c9	terminal	medium	terminal,layers,architecture	What are the main layers involved in terminal behavior?	Terminal emulator, TTY/PTY driver (kernel), shell, and the running program. Each layer contributes different behavior, which is why terminal issues can be confusing.\n\nRemember: "Terminal layers: Emulator → TTY/PTY → Shell → Program." Debug by identifying which layer owns the problem.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/e5f6a7b8c9d0	terminal	medium	terminal,streams,file-descriptors	What are the three standard streams and their file descriptor numbers?	stdin = fd 0, stdout = fd 1, stderr = fd 2.\n\nRemember: "0-1-2: In-Out-Err." stdin=0, stdout=1, stderr=2. Redirect: 2>&1 sends stderr to stdout.\n\nExample: command > output.txt 2>&1 captures both stdout and stderr to the same file.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/f6a7b8c9d0e1	terminal	medium	terminal,redirection,shell	When does the shell set up redirections — before or after the program starts?	Before. The shell opens/creates files and adjusts file descriptors before exec-ing the program, so the program inherits the redirected descriptors.\n\nGotcha: Redirections are processed left to right. 2>&1 > file.txt does NOT capture stderr to file — use > file.txt 2>&1 instead.\n\nRemember: "Redirect the destination first, then point others to it."	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/a7b8c9d0e1f2	terminal	easy	terminal,job-control,signals	How do you suspend a running foreground process and resume it?	Ctrl+Z suspends (stops) it. Then use bg to continue it in the background, or fg to bring it back to the foreground. Use jobs to list current jobs.\n\nRemember: "Ctrl+Z = SIGTSTP (stop/suspend), fg = resume foreground, bg = resume background."\n\nExample: Run a long compile, Ctrl+Z, then bg to continue it in the background while you work.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/b8c9d0e1f2a3	terminal	medium	terminal,TERM,environment	What is the TERM environment variable for?	It tells programs what terminal capabilities are available (colors, cursor movement, etc.). If TERM is wrong, curses-based programs like vim or top will misbehave.\n\nGotcha: If TERM is wrong, colors and cursor movement break. Fix with: export TERM=xterm-256color.\n\nRemember: "TERM tells apps what your terminal can do."	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/c9d0e1f2a3b4	terminal	medium	terminal,escape-codes,rendering	What are terminal escape codes?	Special byte sequences (like ESC[31m for red text) that instruct the terminal emulator to change colors, move the cursor, clear the screen, or switch modes.\n\nRemember: "ESC[ starts most ANSI escape codes." ESC[31m = red, ESC[0m = reset. Programs use these to colorize output.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/d0e1f2a3b4c5	terminal	medium	terminal,stty,recovery	What does "stty sane" do?	Resets the terminal line discipline to reasonable defaults, recovering from broken terminal settings (e.g., after a program crashes without restoring raw mode).\n\nRemember: "stty sane = terminal factory reset." Use it when your terminal is garbled after a program crash.\n\nExample: If you accidentally cat a binary file and the terminal goes crazy: type stty sane and press Enter.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/e1f2a3b4c5d6	terminal	hard	terminal,canonical-mode,raw-mode	What is the difference between canonical mode and raw mode in the TTY driver?	In canonical mode, input is line-buffered — the kernel collects a full line before sending it to the program. In raw mode, programs receive each character immediately, enabling interactive editors and REPLs.\n\nRemember: "Canonical = line mode (normal), Raw = character mode (editors)." Programs like vim switch to raw mode to read each keypress.\n\nGotcha: If a program crashes in raw mode, the terminal stays in raw mode — use stty sane or reset to fix.	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/f2a3b4c5d6e7	terminal	medium	terminal,sighup,jobs	What happens to background jobs when you close a terminal?	The kernel sends SIGHUP to all processes attached to that terminal session, which typically kills them. Use nohup, disown, or tmux/screen to prevent this.\n\nGotcha: nohup only protects against SIGHUP. If the process reads from stdin, it may still die. Use tmux/screen for persistent sessions.\n\nRemember: "tmux > nohup for anything interactive."	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/a3b4c5d6e7f8	terminal	hard	terminal,debugging,troubleshooting	When terminal behavior is weird, what should you check first?	Ask which layer owns the problem: Is it the shell config? The terminal emulator? The TERM variable? The TTY mode (stty -a)? The program itself? Is tmux/screen/ssh adding another layer?	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/b4c5d6e7f8a9	terminal	easy	terminal,quoting,shell	Why is quoting important when passing filenames to commands?	The shell performs word splitting and glob expansion before running the command. Unquoted filenames with spaces, wildcards, or special characters will be split or expanded unexpectedly.\n\nRemember: "Quoting rules: double quotes preserve spaces but expand variables. Single quotes preserve everything literally."	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes
terminal/c5d6e7f8a9b0	terminal	medium	terminal,garbage,escape-codes	What does it mean when you see garbage like ^[[D in your terminal?	An escape sequence is not being interpreted correctly. Either the terminal emulator doesn't support it, TERM is misconfigured, or the output is going to a non-terminal (like a file or pipe).	zines/the.secret.rules.of.the.terminal.wizard.zines.cleaned.notes

<!-- wiki:related:start -->
---

## Wiki Navigation

### Related Content

- [Terminal Internals](../../../../library/topics/terminal-internals/index.md) (Topic Pack, L1) — Terminal Internals

<!-- wiki:related:end -->
