When working an interactive bash session, one aspect from the Windows shell I miss is the F8 key where you start typing a command, hit F8 and the shell finds the most recent command entered in history that matches what you have typed so far. e.g.
me@Ubntu07:~>cd /home/jb<F8 Key Here>
brings up my prior command:
me@Ubntu07:~>cd /home/jboss/server/default/log
Is there any way to do this in bash ?
Answers:
When working an interactive bash session, one aspect from the Windows shell I miss is the F8 key where you start typing a command, hit F8 and the shell finds the most recent command entered in history that matches what you have typed so far. e.g.
me@Ubntu07:~>cd /home/jb<F8 Key Here>
brings up my prior command:
me@Ubntu07:~>cd /home/jboss/server/default/log
Is there any way to do this in bash ?
Answers:
Hit Ctrl-R before you start typing.
(There may well be another version which finds commands based on what's already been typed - I wouldn't know, as Ctrl-R has always been good enough for me :)
Pressing Ctrl-R again shows the next match etc.
Answers:
My Gentoo is configured in a way that I can press PgUp and PgDn to scroll through those commands in the command history that start with what’s currently in my command line.
# cd<PgUp>
results in:
# cd hydrogen
That’s pretty much the same function. It is defined in my /etc/inputrc
with the following lines:
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Answers:
I have these lines in my .inputrc file:
"\e[A": history-search-backward
"\e[B": history-search-forward
This binds history search to the up and down arrow keys. So you can start typing a command, kextload
say, and then each tap of the up arrow will complete the line with the previous command that started with kextload
.
All of my config files are public on github.
http://github.com/jonshea/config-files/tree/master
Answers:
In your case !jb
would print and then run that command.
e.g.,
$ nano logconfig.properties
$ !n
nano logconfig.properties
$
Of course if you want to be on the safe side, use ctrl-r first to bring up the interactive command history.
Answers:
Ctrl + R does a history search. It's a bit different in that first you hit Ctrl + R and then type what you're looking for.
Answers:
If you're just talking about a command, you can use the !<cmd>
to do the last one. For example, say you entered python runscript.py
a while ago; you can type:
!py
or something along those lines to run that command again.
To repeat an argument to a command, you could do something like this:
echo !py:1
which would echo runscript.py
back to the terminal, in this example. The number after the colon refers to the argument you'd like to use from the given command.
There's a lot of other great information about the bash history here.
Answers:
If you use vi input mode (set -o vi in bash or via set editing-mode vi in .inputrc), you can use normal vi commands to search the history (/). This gives you full regular expressions, too, which can be helpful for finding a complex command.