I tend to forget these so I’m documenting them here for posterity.
1. Moving around quickly
ctrl + a
– move to beginning of the linectrl + e
– move to end of the linealt + f
– move forwardalt + b
– move backward
2. ctrl + r
– Search shell history. Keep using ctrl + r
to cycle results. ctrl + g
will preserve what you’ve typed in search and exit the search interface.
3. Clear terminal
$ clear
// or ctrl + l
4. Cut and paste
ctrl + k
– Cut (kill) to end of linectrl + u
– Cut to beginning of linealt + d
– Cut wordctrl + w
– Cut word backwardctrl + y
– Pastes whatever was cut (yank!)
5. Prepend sudo
to previoius command:
$ sudo !!
6. alt + .
– Insert previous command’s argument
7. Unbork your shell
$ reset
My faves include “pushd” and “popd” along with “dirs -v”, all aliased, of course (pu, po, d). Instead of cd’ing to different directories, pushd them onto the stack, popd them off the stack, and “pushd +n” to pull a directory off the stack.
These are great! I’ll be using
pushd
andpopd
constantly. Huge shortcut. Thank you!