Shell Cheatsheet - Shortcuts
Shortcuts (Sorted By Function)
Navigation
Ctrl-a
- Jump to the start of the lineCtrl-e
- Jump to the end of the lineCtrl-f
- Move forward a charCtrl-b
- Move back a charCtrl-xx
- Move between EOL and current cursor position
Edit
Ctrl-d
- Delete character from under the cursorCtrl-w
- Cut word before cursorCtrl-k
- Cut to EOLCtrl-u
- Cut from line start to cursorCtrl-y
- PasteCtrl-t
- move forward character before cursor
Search
Ctrl-r
: search backward.Ctrl-s
: search forward.
For example, to search grep
commands in your history and cycle through alternatives:
Ctrl-r
grep
Ctrl-r
Ctrl-s
Others
Ctrl-c
- Terminate the commandCtrl-z
- Suspend/ Stop the commandCtrl-l
- Clear the screenCtrl-x @
- Show possible hostname completions
Shortcuts (Sorted By Key)
Ctrl
Ctrl-a
- Jump to the start of the lineCtrl-b
- Move back a charCtrl-c
- Terminate the command (SIGINT
)Ctrl-d
- Delete character from under the cursorCtrl-w
- Delete word before cursorCtrl-e
- Jump to the end of the lineCtrl-f
- Move forward a charCtrl-k
- Delete to EOLCtrl-l
- Clear the screenCtrl-r
- Search the history backwardsCtrl-u
- Delete backward from cursorCtrl-xx
- Move between EOL and current cursor positionCtrl-x @
- Show possible hostname completionsCtrl-z
- Suspend/ Stop the command (SIGSTP
)Ctrl-t
- move forward character before cursorCtrl-\
- ifCtrl-c
fails. (SIGQUIT
)
Alt / Opt
Alt-<
- Move to the first line in the historyAlt->
- Move to the last line in the historyAlt-?
- Show current completion listAlt-*
- Insert all possible completionsAlt-/
- Attempt to complete filenameAlt-.
- Yank last argument to previous commandAlt-b
- Move backwardAlt-c
- Capitalize the wordAlt-d
- Delete wordAlt-f
- Move forwardAlt-l
- Make word lowercaseAlt-n
- Search the history forwards non-incrementalAlt-p
- Search the history backwards non-incrementalAlt-r
- Recall commandAlt-t
- Move words aroundAlt-u
- Make word uppercaseAlt-backspace
- Delete backward from cursor
Misc
TAB TAB
- Display all available commands(common)<STRING> TAB TAB
- Display all available commands starting with string./ TAB TAB
- Show entire directory structure including hidden ones.* TAB TAB
- Show only sub-directories inside excluding hidden ones.~ TAB TAB
- Show all present users on system from "/etc/passwd"$ TAB TAB
- Show all sys variables@ TAB TAB
- Show all entries from "/etc/hosts"= TAB TAB
- List output like ls or dir
What if opt does not work on macOS?
On macOS, Opt key can be used instead of Alt. However if Opt-d
prints ∂
instead of deleting the word, try this:
- For Terminal: Settings -> Profiles -> Keyboard -> Toggle
Use Option as Meta key
. - For iTerm2: Settings -> Profiles -> Keys -> Left Option key -> Select
Esc+
.