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 am using LXDE environment in Debian, but I think my question is general. When I have a window opened (i.e. terminal emulator running bash) the window has a window title with the text /bin/bash. When I start mc in the terminal, the title changes to mc [martin@localhost].

The same text also appears as the window name on the window panel, where I can switch between opened windows.

My problem is, the window name does not refresh, it still shows mc [martin@localhost], even when I am already logged on another machine. Only when I start mc does the title refresh again.

Is there a way to make the title refresh automatically?

share|improve this question
up vote 3 down vote accepted

Some programs set the window title and forget to reset it before terminiation.

You can add something like the following lines to your '~/.bashrc' to set the window title before each new bash prompt.

The case statement makes this happen only on terminals known to be capable of changing the window title with an ESCape command. I suggest to add 'screen*' there...

case "$TERM" in
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

These lines come from a '/etc/bash.bashrc' of Debian-6.0.9 and initially are commented out there. Look into your system's '/etc/bash.bashrc', you probably will find some similar lines in there.

The default '~/.bashrc' may contain similar lines. If you do not want to activate this system wide, do it there instead by uncommenting or adding these lines.

When you already are using PROMPT_COMMAND, put the case statement after your preexisting PROMPT_COMMAND definition and write the assignment inside the casestatement like:

PROMPT_COMMAND="$PROMPT_COMMAND;"'echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
share|improve this answer
this works great! Just wondering, what are the characters \033]0; and \007 for ? And why do I need echo ? – Martin Vegter Mar 23 '14 at 18:03
I have just noticed, PROMPT_COMMAND was already set in my .bashrc: PROMPT_COMMAND="history -a; history -c; history -r". What happens if I use your code? Will I loose my previous settings? – Martin Vegter Mar 23 '14 at 18:10
\033 is ESCape, the rest is selecting the desired terminal command and passing parameters to it. Have a look at ctlseqs. – yeti Mar 23 '14 at 19:07

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.