Moving the cursor Go to the beginning of the line (Home). Ctrl+a Go to the End of the line (End).
Hold the Option key ⌥ and click on the current line = Jump BackwardsCtrl+e Previous command (Up arrow). Ctrl+p Next command (Down arrow).
Hold the Option key ⌥ and click on a previous line = Jump upwardsCtrl+n Back (left) one word (Alt-Left arrow). Alt+b Forward (right) one word (Alt-Right arrow). Alt+f Forward one character (Right arrow). Ctrl+f Backward one character (Left arrow). Ctrl+b Toggle between the start of line and current cursor position. Ctrl+xx Editing Clear the Screen, similar to the clear command. Ctrl+L Delete the Word before the cursor. Alt+Del Delete the Word after the cursor. Alt+d Delete character under the cursor. Ctrl+d Delete character before the cursor (Backspace). Ctrl+h Cut the Word before the cursor to the clipboard. Ctrl+w Cut the Line after the cursor to the clipboard. Ctrl+k Cut/delete the Line before the cursor to the clipboard. Ctrl+u Swap current word with previous. Alt+t Swap the last two characters before the cursor (typo). Ctrl+t Swap the last two words before the cursor. Esc +t Paste the last thing to be cut (yank). ctrl+y UPPER capitalize every character from the cursor to the end of the current word. Alt+u Lower the case of every character from the cursor to the end of the current word. Alt+l Capitalize the character under the cursor and move to the end of the word. Alt+c Cancel the changes and put back the line as it was in the history (revert). Alt+r Undo. ctrl+_ Tab completion for file/directory names.
Type just enough characters to uniquely identify the item.
For example, to move to a directory 'sample1'; Type cd sam
Then press TAB and ENTER.[TAB] Special keys: Text Terminals send characters (bytes), not key strokes.
Special keys such as Tab, Backspace, Enter and Esc are
encoded as control characters which are not printable,
they display in the terminal as ^ and are intended
to have an effect on applications.[TAB] Ctrl+I Newline Ctrl+J Enter Ctrl+M Escape Ctrl+[ Many terminals will also send control characters for keys in the digit row: ^@ Ctrl+2 ^[ → Escape Ctrl+3 ^\ Ctrl+4 ^] Ctrl+5 ^^ Ctrl+6 ^_ → Undo Ctrl+7 ^? → Backward-delete-char Ctrl+8 Ctrl+v tells the terminal to not interpret the following character,
so Ctrl+v Ctrl+I will display a tab character,
similarly Ctrl+v ENTER will display the escape sequence for the Enter key: ^MHistory Recall the last command including the specified character(s).
Search the command history as you type. Equivalent to : vim ~/.bash_history.Ctrl+r Previous command in history (walk back). Ctrl+p Next command in history (walk forward). Ctrl+n Go back to the next most recent command.
(beware to not execute it from a terminal because this will also launch its XOFF).Ctrl+s Execute the command found via Ctrl+r or Ctrl+s Ctrl+o Escape from history searching mode. Ctrl+g Repeat last command. !! Repeat from the last command: args n e.g. !:2 for the second argumant. !n Repeat from the last command: args from n to m. e.g. !:2-3 for the second and third. !n:m Repeat from the last command: args n to the last argument. !n:$ Print last command starting with n. !n:p Print the last command beginning with string. !string Quote the last command with proper Bash escaping applied.
Tip: enter a line of Bash starting with a # comment, then run
!:q on the next line to escape it.!:q Last argument of previous command. !$ Last argument of previous command. ALT+. All arguments of previous command. !* Run previous command, replacing abc with def ^abc^def Process control Interrupt/Kill whatever you are running (SIGINT). Ctrl+C Clear the screen. Ctrl+l Stop output to the screen (for long running verbose commands).
Then use PgUp/PgDn for navigation.Ctrl+s Allow output to the screen (if previously stopped using command above). Ctrl+q Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT). Ctrl+D Send the signal SIGTSTP to the current task, which suspends it.
To return to it later enter fg 'process name' (foreground).Ctrl+Z
To use the Alt Key Shortcuts in macOS - Open Terminal Preferences ➞ Settings Tab ➞ Keyboard ➞ Tick "Use option as meta key"
In addition to the standard system-wide and bash keyboard shortcuts, it is possible to add extra key shortcuts for the macOS terminal. These are defined under Terminal ➞ Preferences ➞ Profile ➞ Keyboard
To add the Home key ⇱ for Start of Line and the End Key ⇲ for End of Line:
- Press+to add a new entry
- Select the keyboard shortcut
- Set the Action to Send Text
- Enter the escape sequence: \033[H (for Start of Line) or \033[F (for End of Line)
All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.
Set Vi Mode in bash:
$ set -o viSet Emacs Mode in bash:
$ set -o emacs
“...emacs, which might be thought of as a thermonuclear word processor” ~ Emacs vs. Vi Wiki
How-to: Keyboard Shortcuts for macOS.
Set
Key Bindings - Change the action of keys
Apple Kb HT201236 - Keyboard Shortcuts Quick Reference.
fg - Bring a command to the foreground.
vi editor - A one page reference to the vi editor.
~./.bash_history - Text file with command history.