p_ash-3.2$ cp some_file1234.html /some/loc/ation/ofthe/some_file1234.html.html_Backu

Have been seeing this intermittent issue with the command-line, while typing longer lines as part of any command, after typing some characters, say about 70, it starts all over again, from the extreme left, even before the -bash-3.X$ consequently the prompt and first few characters of the command itself gets overwritten, why would this happen, any workaround?

  • 1
    Do you use tab key to autocomplete?
    – tachomi
    Mar 4 '15 at 14:24
  • 2
    Do you have any escape sequences in your prompt, perhaps to color it?
    – Barmar
    Mar 4 '15 at 17:58
  • 1
    As Barmar hints, this is probably a duplicate of unix.stackexchange.com/questions/28827/… . Check if your prompt contains escape sequences (echo -E "$PS1"). Mar 4 '15 at 22:55
  • Yes, I do use tab, There're no escape sequences, only ls defaults with its colours. Mar 5 '15 at 6:30

Could be a carriage return (\r) in the destination file name.

EDIT: Any chance you previously had your terminal settings messed up? This can happen if you by accident cat a binary file on your terminal. One way to fix that is

 stty sane

Another reason might be that a SIGWINCH got lost when you resized the terminal window. In that case, another resize usually fixes the problem.

  • Didn't see any, any other reason? :( Mar 4 '15 at 12:26
  • @Keys Anything funny going on with the number of columns? Try stty -a and echo $TERM $COLUMNS.
    – Jens
    Mar 4 '15 at 12:29
  • rows 44; columns 168; Shouldn't be a problem. Mar 5 '15 at 6:34
  • Once, I do remember of performing cat on a binary which changed the title of the PuTTY window too with some unreadable content, why was that and how would it affect the $COLUMNS, any preventions in place to avoid this? Mar 5 '15 at 6:41
  • 1
    @Keys There's no prevention from cat'ing binary files other than don't do that. Any modern terminal supports Escape sequences to change a variety of settings. Binary files may contain just the right bytes to mess up the terminal's notion of the number of lines and columns. stty sane is one way to get the terminal back into shape so you at least can see what you type (yes, terminals can be told to not echo typed characters. That's what passwd does.)
    – Jens
    Mar 5 '15 at 8:19

shopt -s checkwinsize in bash can fix this problem sometimes, it arises when the remembered window size differs from the current size. Granted this is usually only an issue with graphical terminals, e.g. konsole mate-terminal, etc.

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.