Use the following keys to do fun things when typing a command in bash (mostly keybindings):
- Use the up arrow to run the previous command
- Continue using the arrow to scroll to commands further in the history
- Use Control-r to search through your command history
- Control-w deletes the last word
- Control-u deletes the line you were typing
- Control-a moves the cursor to the beginning of the line
- Control-e moves the cursor to the end of the line
- Control-l clears the screen
- Control-b moves the cursor backward by a character
- Control-u moves the cursor forward by a character
- Control-_ is an undo
- “man readline” shows the bash keybindings (ymmv per OS)
- Tab completes an argument
- !! repeats the last command. Useful when using sudo in front of the last line from bash
- !$ repeats the last argument for a command
- $_ shows the last word from the previous command
- “cd -” is like a back button
- !!:p outputs the last command with arguments
- cd !!:* cd into the argument from the previous command
- Escape-. expands the argument from the last command
- pbcopy and pbpaste accesses the clipboard from Terminal
- Use ; to separate commands in a single line
- Use | to pipe output to another command
- Use > to send output to a new file, or >> to append output to the end of a file or < to bring input from a file
- “Open .” opens the current working directory in a Finder window
Enjoy!