LWN.net Logo

CLI Magic: Using command history in the bash shell (Linux.com)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 7:37 UTC (Tue) by sveinrn (guest, #2827)
Parent article: CLI Magic: Using command history in the bash shell (Linux.com)

There is one feature I have been missing...

Some years ago I was using MatLab for Windows extensively. There it is possible to type the first few letters of the command and then use arrow-up to get to the previous lines starting with those letters. So when I e.g. has issued a complicated mount command that I need again, and after that 30 other commands, including two other unrelated mount commands, I want to be able to type "mount<up><up><up>" and get back the command I want. Also, something like "*mysource.c<up><up>..." to get all commands containing this text would be nice. I think using the "history" command is too time-consuming, and I usually ends up typing the command again.

Is there anybody that knows how to do something like this?


(Log in to post comments)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 8:27 UTC (Tue) by abovett (subscriber, #13139) [Link]

Not quote the same, but try <ctrl>-R, then type some characters - which will recall the first command that _contains_ those characters. Then hit <ctrl>-R repeatedly until you get to the command you want. Hit Enter to execute it, or Esc to recall it to the current line for further editing.

HTH

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 9:28 UTC (Tue) by gip (subscriber, #20897) [Link]

Quote:
I want to be able to type "mount<up><up><up>" and get back the command I want.

Yes, I had this when I used 4DOS and liked it so I set up bash to do the same thing (it's a "readline" capability, I think).

Create a .inputrc file in your root and put in

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Or whatever your PgUp and PgDn keys output. Next login it should work.
other stuff I use in .inputrc

"\e[2~": kill-whole-line
"\e[3;2~": kill-line

So Ins clears the line and SHIFT-Del clears from the cursor to the end

Hope this helps.

Ciao
G

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 7, 2006 10:39 UTC (Fri) by ekj (subscriber, #1524) [Link]

For many cases, typing C-r mount and then repeatedly C-r until you find the correct one is equally simple.

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 9:34 UTC (Tue) by etienne_lorrain@yahoo.fr (guest, #38022) [Link]

To type the begining of an old CLI command and search backward/forward another command starting with the same chars with PageUp/PageDown, I am using this file for a long time (I think since RedHat 4.2):

$ cat ~/.inputrc
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e0d": backward-word
"\e0c": forward-word
"\e[h": beginning-of-line
"\e[f": end-of-line
"\e[1~": beginning-of-line
"\e[4~": end-of-line
#"\e[5~": beginning-of-history
#"\e[6~": end-of-history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds