Regularly useful bash keys
I use M-x to mean "press alt and x together", C-x to mean "press ctrl and x together" and M-C-x to mean "press ctrl, alt and x together".
- Of course the arrow keys are probably most frequently used. Up/Down move through the history. Left/Right move along the current line. Home/End also move on the current line, but on some terminals they just don't work: Use C-a and C-e instead.
- C-left and C-right go back and forwards by words. On some terminals this just doesn't work: M-b and M-f go back and forwards by one word.
- Enter executes the current line. C-xC-e opens the current line in an editor and runs it when you quit.
- C-o is "operate and get next". It runs the current line and fetches the next one in the history. Apparently undocumented feature: Once it reaches the end of the history, it goes back to where you started. Really handy for "vim; make; run" loops.
- M-. inserts the last word from the previous line. This is probably my favourite. Really useful for "mkdir long_name; cd M-." and similar.
- M-n M-. inserts the nth argument from the previous line.
- M-# makes this line a comment and starts a new line for you. Handy for brief reminders which stay in your history.
- TAB expands words. M-C-e expands the whole line as bash would do before executing it.
- C-x * expands everything matching the current word. E.g. ls /proc/self/fdC-x * → ls /proc/self/fd /proc/self/fdinfo. TAB TAB shows you what it would do.
- M-Backspace kills the word before the cursor. C-y yanks the word from the top of the kill ring.
- C-w and A-d kill the word before and after the cursor, respectively.
- C-r incrementally searches backwards in your history. Ok, this one is my favourite.
- C-d (or whatever EOF is) → Quit!
- If you can't use Alt for some reason (window managers often grab certain keys), just press ESC. M-x === ESC x.
and of course you are all using bash-completion! Write completion scripts for your own programs and deliver them to /etc/completion.d.