I use PuTTY to SSH to my linux server. Today I noticed that when I enter a long command that goes beyond the right hand of the screen, instead of wrapping down to the next line, the text starts at the left of the screen on the same line, writing over the top of the characters. I can't figure out what might have changed to cause this. Can anyone give any pointers at what might cause this, and how to resolve? I have Auto wrap mode initially on ticked in PuTTY.

I haven't made any changes to the PuTTY settings for this server, so at a loss why this stopped working correctly.


After submitting the question, I had better thought it out, and another search on Google gave me this which pretty much explains it:


My fancy PS1 string was: PS1='\e[0;32m[\u\e[m@\h \W]\$ ' but this included non printing characters (the \e parts which change colour of the username). I needed to escape these non printing characters using \[. The following fixed the issue:

PS1='[\[\e[0;32m\]\u\[\e[m\]@\h \W]\$ '

This results in output like this:

[username@hostname cwd]$

With the username coloured green.

I had edited my PS1 lines so that normal users had their username in red, but if su'd to root, root would be in red (\e[0;31m in case you are interested). I guess since I did that I didn't enter any long commands...

  • 3
    I had also "hand-tuned" my PS1 string; thanks for that hint! But instead of fixing my broken one, I decided to build a new one with a fancy generator: bashrcgenerator.com - in case somebody else is as lazy as me ;) – codeling Sep 8 '16 at 23:00
  • I had a similar problem when using \033 where @dunxd uses \e, even though it was escaped as in this answer. – Dan Sep 26 '17 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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