Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

I have an issue where if I type in very long commands in bash the terminal will not render what I'm typing correctly. I'd expect that if I had a command like the following:

username@someserver ~/somepath $ ssh -i /path/to/private/key

The command should render on two lines. Instead it will often wrap around and start writing over the top of my prompt, somewhat like this:

myreallylongusername@something.somelongserver.comh -i /path/to/private/key

If I decide to go back and change some argument there's no telling where the cursor will show up, sometimes in the middle of the prompt, but usually on the line above where I'm typing.

Additional fun happens when when I Up to a previous command. I've tried this in both gnome-terminal and terminator and on i3 and Cinnamon. Someone suggested it was my prompt, so here that is:

\[\033[01;32m\]\u:\[\033[01;34m\] \W\033[01;34m \$\[\033[00m\]

Ctrll, reset, and clear all do what they say, but when I type the command back in or Up the same things happens.

I checked and checkwinsize is enabled in bash. This happens on 80x24 and other window sizes.

Is this just something I learn to live with? Is there some piece of magic which I should know? I've settled for just using a really short prompt, but that doesn't fix the issue.

share|improve this question
So using the command env -i bash --norc fixes it. The $COLUMNS and $LINES match. Does that mean that there's something funny with my .bashrc? – Muricula Dec 20 '13 at 0:44
So I commented out my .bashrc and wound up isolating my prompt as the problematic part, specifically the coloration syntax involved. What's wrong with the PS1 above? – Muricula Dec 20 '13 at 0:53
\[\033[01;32m\]\u: \[\033[01;34m\]\W \[\033[01;34m\] \$ \[\033[0m\] seems to avoid the weirdness in the behavior - but don't know if it respects your original prompt completely... – On a eu. Dec 20 '13 at 1:19
up vote 40 down vote accepted

Non-printable sequences should be enclosed in \[ and \]. Looking at your PS1 it has a unenclosed sequence after \W. But, the second entry is redundant as well as it repeats the previous statement "1;34".

\[\033[01;32m\]\u:\[\033[01;34m\] \W\033[01;34m \$\[\033[00m\]
                  |_____________|               |_|
                         |                       |
                         +--- Let this apply to this as well.

As such this should have intended coloring:

\[\033[1;32m\]\u:\[\033[1;34m\] \W \$\[\033[0m\]
                                  +---- Bold blue.

Keeping the "original" this should also work:

\[\033[1;32m\]\u:\[\033[1;34m\] \W\[\033[1;34m\] \$\[\033[0m\]
                                  |_|         |_|
                                   |           |
                                   +-----------+-- Enclose in \[ \]


The reason for the behavior is because bash believes the prompt is longer then it actually is. As a simple example, if one use:

       1 2345678

The prompt is believed to be 8 characters and not 1. As such if terminal window is 20 columns, after typing 12 characters, it is believed to be 20 and wraps around. This is also evident if one then try to do backspace or Ctrl+u. It stops at column 9.

However it also does not start new line unless one are on last column, as a result the first line is overwritten.

If one keep typing the line should wrap to next line after 32 characters.

share|improve this answer
If you have - or anyone - has an explanation as to what exactly in the original sequence caused the line to repeat over itself, I'd be interested in knowing that. Also +1 for how you showed this visually. – On a eu. Dec 20 '13 at 2:42
@illuminÉ: Have not looked at the source, but added an update with a note on behavior from observation. – Runium Dec 20 '13 at 3:26
Oh my god, I can't believe I just found an answer to this obscure problem with a single google search. Thank you. – Artur Sapek Jun 15 '15 at 21:00
Just in case you are facing any problems, you can use this website to create a new one - bashrcgenerator.com – divinedragon Dec 11 '15 at 6:12
omg this was a low-level annoyance for MONTHS before I finally googled it and got here. Thanks @Sukminder! – MikeTwo Mar 26 at 19:18

It is mostly to do with the size of the window assumed by the terminal is not the same as your actual window size. If you are using bash, you can try this.

$ shopt  | grep checkwinsize

If you don't get

checkwinsize    on

Then activate it with

$ shopt -s checkwinsize

Then just attempt running another command (like ls) or resizing the window once, the above works for me every time.

For Redhat systems particularly, the issue is often caused by misconfiguring ~/.bashrc not to call /etc/bashrc. Normally, bash loads ~/.bashrc which is expected to call /etc/bashrc, which by default contains shopt -s checkwinsize.

share|improve this answer
I've been fighting this issue with terminator for years, and this post solved it. Thanks. – Dev Dec 29 '14 at 19:48
+99 if only I could. – kubanczyk Apr 20 '15 at 8:52
Solved for me as well. Thanks! – jbwiv May 27 '15 at 20:33
Had the same problem with OS X, apparently if you call "login" to start your terminal, it starts bash in a way that reads /etc/bashrc, but if you just call straight to bash, the ~/.bashrc doesn't source things by default so you get the odd wrapping effect. Thanks! – rogerdpack Sep 11 '15 at 22:16
This worked for me as well. Colors were not on in this particular server, calling correct /etc/bashrc, everything else was good to go...turns out this is the cause of the wrapping issues. – dhaupin Nov 20 '15 at 20:23

This sounds like an issue with your COLUMNS & LINES environment variable settings. When you resize the window they're typically set automatically by gnome-terminal (I believe) you can force them to be manually set by issuing the command resize.


If I resize my gnome-terminal to 79x17 my variables show up like so:

$ echo $COLUMNS; echo $LINES

I can force it like so:

$ resize
share|improve this answer
Interesting, but doesn't help. – Muricula Dec 19 '13 at 22:57

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.