Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ctrl+r is a great little tool for searching your .bash_history for previously run commands.

However, when I use it in my OS X I see weird behavior, and I was wondering if anyone else sees the same thing or knows how to fix it.

  1. Ctrl+r
  2. type in something like find
  3. oh cool,'s the command I wanted find . -exec grep -q "hello world" '{}' \; -print
  4. I want to run that command but change hello world to something else.
  5. So I hit or
  6. Now the command is SORTA on the command line but it always looks like some trunctated version of the command, like this: -q "blog_posts_by" '{}' \; -print, where the whole command is there, and I can use the cursor keys to move around on the line, but not all of it is printed. There is a disconnect between what is shown on the line and what the terminal actually thinks I am editing.

Does anyone have a clue why this might happen? It's not an easy phenomenon to search the webs for.

share|improve this question
Does this only happen on lines longer then your term window width? – Essobi Jan 19 '11 at 18:03
What version of Terminal.App/OSX are you running BTW? Bash version? Can you show us your .bashrc as well? – Essobi Jan 19 '11 at 20:07
up vote 9 down vote accepted

You probably have escape sequences for colors in your prompt that are not properly delimited. They need to be enclosed in \[ and \].

PS1='\[\033[1;36m\]\u\[\033[0m\]@\[\033[1;34m\]\h\[\033[0m\]\$ `

The length of non-printing character sequences are not included in the length of the prompt when they are thus enclosed and the position of previous commands needs to be calculated for proper display when they wrap.

share|improve this answer
Thanks a bunch. This was exactly the problem. – bryan kennedy Jan 21 '11 at 19:02
OK, I had a few more problems, that were solved by the answerer over on this StackOverflow thread -… – bryan kennedy Jan 22 '11 at 23:19
This applies to newlines in the prompt, too. I had a hicolor control sequence dropped because it was at the beginning of PS1, but not again after the newline char within. – Walf Mar 11 at 2:09

This could be due to the way the escape keys are configured on your Terminal, what I normally do is use the left or right arrow on iTerm or since I'm not a fan of hitting return immediately, does that work for you?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.