Shortcuts to improve your bash & zsh productivity

So, you hate using a terminal? That might be, because you use the arrow keys to navigate character by character through a long command just to change a paramater at the other end of the line, right? Here's a list of my most-used bash & zsh shortcuts, that will definitely boost your productivity and will help you to improve your command line experience.

ShortcutAction
CTRL + AMove to the beginning of the line
CTRL + EMove to the end of the line
CTRL + [left arrow]Move one word backward (on some systems this is ALT + B)
CTRL + [right arrow]Move one word forward (on some systems this is ALT + F)
CTRL + U (bash)Clear the characters on the line before the current cursor position
CTRL + U (zsh)If you're using the zsh, this will clear the entire line
CTRL + KClear the characters on the line after the current cursor position
ESC + [backspace]Delete the word in front of the cursor
CTRL + WDelete the word in front of the cursor
ALT + DDelete the word after the cursor
CTRL + RSearch history
CTRL + GEscape from search mode
CTRL + _Undo the last change
CTRL + LClear screen
CTRL + SStop output to screen
CTRL + QRe-enable screen output
CTRL + CTerminate/kill current foreground process
CTRL + ZSuspend/stop current foreground process
CommandAction
!!Execute last command in history
!abcExecute last command in history beginning with abc
!abc:pPrint last command in history beginning with abc

History Search

Press CTRL + R to search through the history. Continue pressing CTRL + R until you find the entry you're looking for. Press [ENTER] to execute the current expression. Press [Right Arrow] to modify the current expression. Press CTRL + G to escape from search mode.

Special setup for Mac OS X

Go to Terminal -> Preferences -> Settings -> Keyboard
  • To enable the use of the ALT or OPTION key, select use option as meta key
  • To enable the CTRL + [left arrow] and CTRL + [right arrow] shortcuts, select
    • control cursor left and set it to \033b and
    • control cursor right and set it to \033f.
You know of any other important shortcuts that I missed? Please let me know in the comments.

1 comment:

  1. This is just what I needed! Thank you for your help!

    ReplyDelete