If any of you ever used Matlab, you might have noticed the command window functionality in that program. I wonder if it is possible to enable the same functionality in Mac Terminal.

It works like this: suppose you have used two commands previously in this Terminal session. First you used a cd ~ and then a ls -la.

In every *nix terminal, including Mac's, if you hit the Up Arrow, it'll first show the ls -la command and, if you hit it twice, the cd ~ command. This is great. But, in Matlab, if you first type the letter c and then hit Up Arrow, it won't show you ls, but instead go directly to cd ~. This saves a lot of time when you have big commands and a long list of previously used commands.

Is it possible?

6 Answers 6


In a Bash shell, you can hit Control+R to do a reverse intelligent search in the history. Start typing the command and the shell will autocomplete with previously entered commands.

Then you can either press Enter to execute the command again, use the arrow left or right key to edit the command, or keep pressing Control+R to cycle through other possible completions.

Reverse intelligent search


Save this as ~/.inputrc:

# make the up and down arrows cycle through commands that match the start of a line
"\e[A": history-search-backward
"\e[B": history-search-forward

Option-up would be \e\e[A and control-p \C-p. You can see the escape sequences of other key combinations by pressing control-v.

  • 1
    For users who don't yet have ~/.inputrc, just create one. Jul 23, 2016 at 4:24
  • 2
    "\e[A": command not found
    – Louis
    Sep 6, 2018 at 10:18

Another thing you can do is type ! and then the first letter, and it will find the most recent. IE: cd ~ can be accessed with !c


This is a feature of the shell. Control-R will do what you describe, but changing to a more modern shell will get you so much more. Take a look at Z-shell (zsh), there is a bit of a learning curve, but it is very powerful.

  • I think you mean Control-R.
    – jmk
    Feb 2, 2013 at 20:30

zsh will complete commands exactly like in your example. You don't even have to do anything other than use it for your shell.


Add these to your .cshrc (if you are using tcsh) --

  bindkey -k up history-search-backward
  bindkey -k down history-search-forward

Then do source ~/.cshrc to get exactly the functionality you describe.

I don't know if there is a .profile equivalent.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .