Technology, mountain biking, politics & music.

Archive for the ‘bash’ tag

Bash 101

without comments

Reposting from the internal Workingmouse blog…

If anyone does any significant work in a shell, using keyboard shortcuts makes life so much easier. I find myself writing these out all the time, so here they are for posterity (these are Emacs bash bindings, not vi). Meta is the Alt key on most systems (you’ll have to enable this on the Mac and turn off Alt access to menus on Ubuntu), so replace Alt in the below examples. Meta is also almost always Escape, however, you cannot hold down the escape key (say to go 2 words back), you must release it and press it again.

Moving around

  • Ctrl-a – Cursor to start of line.
  • Ctrl-e – Cursor to end of line.
  • Meta-b – Move word back.
  • Meta-f – Move word forward.

Editing text

  • Ctrl-d – Delete character forward (same as the Delete key on most systems).
  • Ctrl-u – Delete to start of line.
  • Ctrl-k – Delete end of line.
  • Ctrl-w – Delete work back. Uses whitespace as boundary, so is good for deleting arguments to commands.
  • Meta-d – Delete word forward.
  • Meta-Backspace – Delete word back. Does not use whitespace as boundary.


  • Ctrl-p – Previous entry in history (also up arrow).
  • Ctrl-n – Next entry in history.
  • Ctrl-o – Execute current command (out of history) and show the next history entry.
  • Ctrl-r – Reverse search in history.Press again to search further back, Enter or Ctrl-o to execute.
  • Enter – Execute current command.
  • Meta-. – Paste in the last argument of the last command. Press again to go further back in history.


  • Ctrl-l – Clear screen.

More information is available on the Man page for sh (note that this is Apple’s implementation but has good verbage).

Written by Tom Adams

September 11th, 2008 at 10:18 am

Posted in Technology

Tagged with ,