Super User is a question and answer site for computer enthusiasts and power users. 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

How can I set the window title in Bash? I do know that in Windows Batch it is TITLE.

share|improve this question

migrated from Dec 17 '09 at 19:08

This question came from our site for professional and enthusiast programmers.

=> – T.J. Crowder Dec 17 '09 at 17:24
it's kind of programming related, sorta... – Stefano Borini Dec 17 '09 at 17:27
Similiar to this question?… – Darren Hall Dec 22 '09 at 3:40
up vote 7 down vote accepted

Here is a nice function to do it:

# Allow the user to set the title.
function title {
   PROMPT_COMMAND="echo -ne \"\033]0;$1 (on $HOSTNAME)\007\""

Put that in your ~/.bashrc, then type "title whatever" to set the title. If you want to get rid of the hostname, remove "(on $HOSTNAME)".

Edit: make sure to . ~/.bashrc (aka source ~/.bashrc) before trying, of course.

Source link.

share|improve this answer
How can i just do everything in the code? I dont want the user to type it in. – YourComputerHelpZ Dec 17 '09 at 17:28
You could have your bash code call the title function. – danben Dec 17 '09 at 17:33
it does not work, when i enter the function stuff, and then enter this title Hey!, it does not work. What to do? – YourComputerHelpZ Dec 17 '09 at 17:45
At the risk of repeating myself, did you remember to execute your bashrc script after editing it? It works fine for me. – danben Dec 17 '09 at 18:09
@YourComputerHelpZ: are you using an xterm, or another kind of console such as Konsole or yakuake ? – ℝaphink Dec 18 '09 at 16:17

We need more information: The answer will depend on what terminal you're using, not what shell. Is this in an xterm? An rxvt? A cygwin window on windows? Etc.

(danben's answer works for xterms, and probably for rxvt terminals)

share|improve this answer
i use Terminal on Linux Mint – YourComputerHelpZ Dec 17 '09 at 17:54

I have this VT100 escape sequence defined in .bashrc.


PS1="${PS1_SET_TITLE}" my other prompt components

export PS1

For my home directory it displays alex@host:~, when I change directories, they are updated in window title.

Works with CYGWIN and PuTTY terminal sessions. I usually don't run X, but when I did it worked fine with XTerm.

Read PROMPTING section of bash man page on available switches for PS commands, e.g \u \h \w.

share|improve this answer

If you are using "mintty" (the default terminal of Cygwin since end 2011), add the following in .bashrc :

function title {
   export WINDOWTITLE=$1
export PS1='\[\e]0;$WINDOWTITLE:\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]~\w\[\e[0m\]\n\$'

and reopen your terminal and type "title ThisIsMyTitle"

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.