Essential Commands
These commands form the foundation of daily shell work. Combine them with pipes and redirection to build powerful workflows.| Command | Purpose |
|---|---|
echo | Print text or variable values to the terminal |
cat | Display file contents or concatenate multiple files |
less | Page through file contents (supports search with /) |
more | Simpler pager for scrolling through output |
head | Show the first N lines of a file (default 10) |
tail | Show the last N lines of a file (default 10) |
grep | Search for patterns in text using regular expressions |
wc | Count lines (-l), words (-w), or bytes (-c) |
sort | Sort lines alphabetically or numerically |
uniq | Remove or report duplicate adjacent lines |
cut | Extract fields or character ranges from each line |
tr | Translate or delete characters (e.g., lowercase to uppercase) |
Input/Output Redirection
By default, commands read from standard input (stdin) and write to standard output (stdout), with errors going to standard error (stderr). Redirection operators let you point these streams to files instead.Use
>> instead of > when you want to add output to an existing file rather than replace it. Using > on an existing file silently overwrites its contents.Pipes
Pipes (|) connect the stdout of one command directly to the stdin of the next, letting you build multi-step processing chains without temporary files.
Useful Command Examples
Environment Variables
Environment variables store configuration values that are available to your shell session and the programs you launch from it.View a variable
Prefix the variable name with
$ to expand its value. Use echo $VARIABLE_NAME to print it.Set a temporary variable
Run
export MY_VAR="value" to create a variable available to the current session and any child processes. It disappears when you close the terminal.Keyboard Shortcuts
These shortcuts save time and are worth memorising from day one.| Shortcut | Action |
|---|---|
| Ctrl+C | Interrupt (terminate) the running command |
| Ctrl+D | Send EOF; exits the shell if the prompt is empty |
| Ctrl+Z | Suspend the foreground process (resume with fg or bg) |
| Ctrl+R | Reverse search through command history |
| Tab | Autocomplete commands, file names, and paths |
| Ctrl+L | Clear the terminal screen (same as clear) |
| Ctrl+A | Move cursor to the beginning of the line |
| Ctrl+E | Move cursor to the end of the line |
| Ctrl+W | Delete the word before the cursor |
Command History
Bash keeps a record of every command you run, stored in~/.bash_history.