I like the MATLAB way of input command — it has the same tab-complete feature; in addition, it has a up-arrow-auto-complete-history-command feature. For example, if I have typed a command “x=39;y=23;” before, now I can just type “x” and then type the up arrow button, then this command would auto-complete. It can also switch between all the history commands that has the same starting letters.
Vert unfortunately, I haven’t found any similar feature in the Linux terminal, or say bash. There is a command called “history” that can list all the history commands. I can type “history | grep xxx” to search the command I want to find. The same example, I can type “history | grep x=” try to find that command. There would come up something like “201 x=39;y=23;“. The number in the beginning is the index of in the history. Then I can type “!201” to repeat this command. But I find this quite time-consuming.
Then I came across a shortcut of bash “Ctrl + R“, it can “search through previously used commands”. Say in the terminal I type “Ctrl + R”, then “(reverse-i-search):” came up, then I can type keyword of my previous command, say “x=” then the most related command would come up. After the right command comes up, then type enter, finish. Although not as convinient as the MATLAB mode, this is way better than using “history” command, in my view.
Excellent! I’ve been looking for something like this for a while. Thanks!
Neat, thanks
Second thought : I’ve posted your tip in French, linking to your blog page. I hope it’s okay with you 😉
http://bapoumba.free.fr/?p=78
To bapoumba: That’s totally ok, I am pleased to share with others. In addition, I did not invent this, I just read this from somewhere else :). Thanks for sharing this.
Well if you will not miss job control, you can use ipython, which is an awesome python shell, that has a shell like environment (to start it use ipython -p pysh). You can then have the exact matlab feature you want.
Suppose I have done a search like,
fine . -name ‘*.tex’
Then the next time I want to use it I simply type
find
it will even cycle through all previous find commands, etc.
(Combine this program with numpy and you also have a basic matlab replacement 🙂
This ipython is quite nice! thanks
Something even better (and actually what you want).
Go to /etc/inputrc and find the line with history search and page-up/down, and uncomment it.
Voila history search with Page-Up/Down from the letter in front of the cursor.
Thanks! Great advice!
Hey,
The way to do this “like MATLAB” is by adding the following lines in your .bash_profile or .bashrc file (and subsequently running source .bashrc, etc):
bind ‘”\M-[A”: history-search-backward’
bind ‘”\M-[B”: history-search-forward’
These are the keybindings I use for bash 3.2 on Mac OS X, so you might have to find other keybindings specific to your machine, but the general syntax is there! Enjoy!
Many thanks!
Thanks a lot!!!
Another tip:
Pressing Ctl+R again while searching will skip the latest command that is found and go on to the next one.
Thanks a lot!!!
When i use up arrow to see or use the earlier commands, it does’nt show or list out.
Who is one person who has been influential in your life, for better or worse?
Awesome, this is sweet
Thanks! I have been looking for a solution to this problem for a long time!!
This is very useful, I’ve been searching for this for so long. Thanks
web page
Thank you, I’m glad I came across this site.
thanks, that helped!
The most obvious technique is missing from the comments above. If one uses VI Editing Mode (I assume most of the readers are), searching through history with / ? n and N is simple.
If you don’t add one line, “set -o vi”, to your ~/.bashrc file
See for example “Readline VI Editing Mode Cheat Sheet” at http://www.catonmat.net
Thanks helped a lot
How to search partial matching commands with history?
if you type ctrl+r and write, for example “cd”, you can search among every “cd” command saved in history!
ctrl + r , saves ot of time
This is the guide to previous commands search and edit: http://www.cyberciti.biz/faq/linux-unix-shell-history-search-command/
use this http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
then all you need is to type x and hit upward arrow until you see your command
or summarized
in terminal enter:
sudo gedit ~/.inputrc
then copy paste and save
“\e[A”: history-search-backward
“\e[B”: history-search-forward
“\e[C”: forward-char
“\e[D”: backward-char
FROM now on [and many agree this is the most useful tool]
all you need to do to find a previous command is to enter say the first 2 or 3 letters and upward arrow will take you there quickly
all i need to do is enter ff and hit upward arrow command will soon appear
[…] https://weichen.wordpress.com/2007/01/20/howto-quick-search-terminal-history-commands/ […]
Reblogged this on MyWayOnRails.
This is exactly what I wanted.
Thanks a million.
Thanks a lot!
Thanks..Helps a lot
Thank you….very helpful!!!!!
YES! I would’ve shot you some Dogecoin if you had a donation address somewhere. Thanks.
Love it! Thanks!
When your kitty kicks litter throughout the flooring, simply use a larger pot. A huge, roomy tote rich in sides creates a good litter box. A large spherical bathtub also will make a very good cat litter box. A cafe or restaurant sizing tour bus tub is a capacious cat litter box. Providing higher ends and a lot more space will solve your cat’s litter kicking problem.
Love it!