Thursday, November 20, 2008

Bash Readline Commands

One of the cool things about most versions of the Linux command line is that you get a built in text editor to allow you to move around and edit your line easily. I generally use the Bash shell, and that comes with Readline. I know a few commands by heart and use them constantly, but there are more that never quite stick in my head. So, I figured I'd write about them here so they'd be easy to find and, possibly, pressed a little more firmly into my gray matter by virtue of having written them down.

Ctrl-e Go to the end of the line
Ctrl-a Go to the start of the line
Alt-f Go forward one word (actually Meta-f, but Meta is usually Alt)
Alt-b Go backward one word

Ctrl-k Kill the text from the current cursor point to the end of the line
Alt-d Kill the text from the current cursor to the end of the word
Alt-DEL Kill the text from the current cursor to the start of the word
Ctrl-w Kill the text from the current cursor to the previous white space
Alt-DEL and Ctrl-w are different because the "word boundaries" are different. Alt-DEL will stop at punctuation and other non-word characters. Ctrl-w does not.
Ctrl-y Yank (paste) the most recently killed text into place at the current cursor

Ctrl-l Clear the screen, putting the current line at the top


Ira said...

and what about searching history with ctrl-R? there are many more. and this is the default Emacs mode. there's also a VI mode :-)

other shortcuts I really like are not readline specific, they are "!!" for the full string of the previous live, and "!$" for just the last parameter of the prev. line, and many others are listed in the info pages (and probably also the MAN)


Shlomi Fish said...

I once went over all the Bash Readline commands in the Bash man page and wrote a post with the ones I found the most useful. Enjoy!