Reference · Bash · from Lesson 01
The compressed version. Built for re-reading and printing, not for learning from cold.
-l. Bundles: -la is -l -a.--color. GNU/Linux convention; often absent on macOS.| Move | When to use it |
|---|---|
| man cmd | The offline manual. Space pages down, /word searches, q quits. |
| cmd --help | Quick summary. Works on Linux/GNU tools; often fails on macOS. |
| which cmd | Shows which file actually runs when you type that name. |
| type cmd | Like which, but also reveals shell builtins and aliases. |
| explainshell.com | Paste a whole command; it labels every part. Best tool for decoding someone else's script. |
| Form | Means |
|---|---|
| logs/app.log | Relative — starts from your current directory. |
| /var/www/html | Absolute — starts at the top of the disk. Same everywhere. What scripts use. |
| ~ | Your home folder. ~/Desktop works from anywhere. |
| . | The current directory. |
| .. | The parent directory. cd .. goes up one level. |
| - | With cd only: the directory you were in before. A fast toggle. |
| Command | Does |
|---|---|
| pwd | Print working directory — where am I? |
| ls | List contents. -l long form, -a include hidden, -h human-readable sizes. |
| cd dir | Change directory. Bare cd returns home. |
| cat file | Dump a whole file to the screen. Fine for short files. |
| less file | Page through a long file. Same keys as man; q quits. |
| head / tail file | First / last 10 lines. tail -f follows a log live. |
| grep pat file | Print lines matching a pattern. -c counts, -i ignores case, -n shows line numbers. |
| Key | Does |
|---|---|
| Ctrl-C | Cancel the running command. The universal escape hatch. |
| Ctrl-D | End of input / exit the shell. |
| Ctrl-L | Clear the screen. |
| Ctrl-A / Ctrl-E | Jump to start / end of the line. |
| Tab | Autocomplete a name. Press twice to list options. Use constantly — it prevents typos. |
| Up arrow | Previous command. history lists them all. |
| q | Quit man and less. Worth burning into memory. |
Your Mac's tools come from BSD; most servers use GNU. Same names, different flags.
| Thing | Your Mac | Linux server |
|---|---|---|
| default shell | zsh | usually bash |
| bash version | 3.2.57 (2007) | 5.x |
| ls --help | fails | works |
| sed -i | needs an argument: sed -i '' | sed -i alone |
| declare -A, mapfile, ** | unavailable (bash 3.2) | available |
To get a modern bash locally: brew install bash. Not needed yet.
rm deletes permanently. There is no recycle bin. rm -rf dir removes a folder and everything inside without asking.
Habits that save you: run ls on a path before you rm it; use rm -i to be prompted; never paste an rm, sudo, >, or curl … | bash line you can't read aloud. > silently overwrites a file — it is quietly destructive too.