This is a list of my personal “hard-to-remember” bash shortcuts that I don’t know by heart (but should), even after years of using bash.
Ctrl+U
Delete all characters before the cursor (Opposite of CTRL-K
)Ctrl+XX
Move between the current cursor position and the start of the command line (pressing multiple times goes back and forth).Ctrl+T
Transpose: Swap the last two characters.Alt+T
Transpose: Swap the last two words.Alt+R
Undo all changes made to this line (useful when editing a command from history)Alt+.
Insert the last argument from the previous command line. Similar to writing !$
(Alternative Shortcut: Alt+_
)1One I sometimes try hard to remember is
Alt+*
(which is Alt-Shift-+
on German keyboards)This one is similar to Tab-Tab, but writes the completions on the command line, so you can edit them. Great if you want to run on all files matching the completion, except for one.
Another arcane one that could potentially be useful is
Alt+Tab
Complete from history. Great for completing longish arguments that you used before.It is unfortunately bound by the window managers to switch the active window. However, combinations with Alt (or Meta, as bash’s man page would say) can be replaced by sequencing with Escape instead. Use the sequence Esc, Tab
, i.e. first Escape, then Tab. As with regular Tab
completion, if there is more than one possibility you need to do it twice. In the sequence version that is Esc, Tab, Esc, Tab
.
There is also a host of similar completion commands for special completions. They come in two versions: The symbol together with Alt
(e.g. Alt+/
) to insert the possible completions or after Ctrl-x
(e.g. Ctrl-x, /
) to just show them.
/
Complete file names$
Complete variable names@
Complete host names!
Complete command names~
Complete user names (from /etc/passwd apparently)There are many more shortcuts, but for many I feel I won’t need them often enough to ever memorize them, e.g. (un)capitalization.
There is even a more powerful (and complex) command for picking arguments from the previous command line: Alt+Ctrl+y
. By itself, it inserts the first argument (excluding the command, i.e. it picks the second word). However, it can be prefixed by, e.g., Alt+5
to pick the fifth argument (i.e. the sixth word) from the previous command line. It is even be possible to use negative numbers to count the arguments from the back by starting with Alt+-
(then release Alt
and enter a digit).↩