# Files and Text ## Basic file operations - `touch ` — create an empty file (or update its timestamp if it exists) - `mkdir ` — create a directory (`-p` creates any missing parent directories too) - `cp ` — copy a file - `mv ` — move OR rename a file (Linux treats renaming as "moving to a new name in the same place") - `rm ` — delete a file (`-r` for a directory, `-f` to skip confirmation — dangerous combined: `rm -rf` deletes without asking, permanently) ## Reading text - `cat ` — print the whole file at once - `less ` — page through a file interactively (press `q` to quit) — the right tool for anything too long to read in one screen - `head ` / `tail ` — the first/last 10 lines by default (`-n 20` for a different count); `tail -f` follows a file live as new lines are appended — exactly how you'd watch a log file update in real time ## Searching text: `grep` `grep PATTERN file` prints only the lines matching PATTERN. This is one of the most-used commands in real operations work — "find the lines that matter" beats "read everything." ## Pipes and redirection: composing commands - **A pipe (`|`)** sends one command's output as the next command's input: `cat app.log | grep ERROR` — read the file, then filter it. - **Redirection (`>`)** sends a command's output into a file instead of the screen (overwriting it): `grep ERROR app.log > errors.txt`. `>>` appends instead of overwriting. ## stdout vs. stderr A command actually has TWO separate output streams: **stdout** (normal output) and **stderr** (error messages), even though both print to your screen by default. This is why `command 2>/dev/null` (redirecting stream `2`, stderr, to nowhere) can suppress error noise while still showing normal output — you'll use exactly this pattern in later Labs. ## Instructor Notes **Lesson goal:** Build real fluency composing small commands together — this is the single highest-leverage Linux skill for troubleshooting work later in ROOT_. **Approximate timing:** 15 minutes read; 10 minutes live. **Common misconception to watch for:** students often don't realize stdout/stderr are separate streams until they see `2>/dev/null` change what's suppressed — worth demonstrating live. **Demo idea:** run a command that produces both real output and an error in the same call (e.g. `ls /etc /nonexistent`) and show how `2>/dev/null` changes what appears.