Regularly Useful Bash Keys

Bruce Duncan

Bruce.Duncan@ed.ac.uk

Using bash every day?

You probably already

  • Use tab completion
  • Use arrow keys
  • Have a shiny prompt

Using bash every day?

This talk is not about

  • Job control
  • Redirection
  • Scripting
  • and other magic...

I'm going to read you the man page

bear with me...

When I say...

  • M-x I mean Alt-x
  • C-x I mean Ctrl-x
  • C-M-x I mean Ctrl-Alt-x

 

If you can't use Alt, press ESC.

M-x === ESC x

Navigating a line

  • Arrow keys, Home/End, C-left/right
  • But if they don't work in your terminal:
  • C-a/C-e, M-b/M-f

Making it go

  • Enter runs a line
  • C-xC-e opens the line in an editor
  • C-o does "operate and get next"

Grab previous arguments

  • M-. inserts the last argument from the previous line
  • M-n M-. inserts the nth argument from the previous line.
  • Keep pressing!

Take notes

  • M-# makes this line a comment and starts a new one.
  • So you have a little record in your history.

Expand

  • TAB expands a word of course
  • C-x * expands everything
  • M-{ expands everything into braces!
  • M-C-e expands the whole line as bash would before executing it.

Clipboard (kill/yank)

  • M-backspace and C-w kill the previous word
  • M-d kills the next word
  • C-y yanks previous kills into the buffer (aka paste)

History search

  • C-r searches incrementally backwards in your history

Like, literally

  • C-v inserts the next character verbatim, e.g. TAB

Bye!

  • C-d is EOF → Quit!