Mac OS X Change the Terminal Window Title
The title of the Mac OS X terminal window can easily be changed. Changing the title can be useful when running a script or when using multiple terminal windows for different purposes in order to identify them easily when switching between applications and windows.
In the terminal window, from a bash prompt (the default shell) or in a bash shell script, use the following command to change the terminal window title to Tech-Recipes rules:
echo -n -e "\033]0;Tech-Recipes rules\007"
You can place (just about) any text in place of “Tech-Recipes rules” including the contents of a variable. Consider the following example:
name=`hostname`
echo -n -e "\033]0;$name\007"
This will change the title of the terminal to the hostname of the computer running the shell.
The Conversation
Follow the reactions below and share your own thoughts.

November 08, 2008 at 8:46 pm, des09 said:
How would you set the tab title when running multiple tabs?
April 27, 2009 at 7:48 am, luca said:
Thanks, works like a charm. However, it doesn’t change the title of a tab, just that of the main windows in which many tabs are contained – so it’s useless to be able to see at a glance which terminal is the one you’re looking for.
November 20, 2009 at 4:33 pm, Anonymous said:
Perfect, I put this in my .bashrc and the title changes on each tab as I login
echo -n -e “33]0;`hostname`07″
The only problem I have is that it doesn’t change back, when I get logged out, so I have an alias to reset it…
alias sett=”echo -n -e “33]0;`hostname`07″
November 20, 2009 at 4:48 pm, Anonymous said:
I put this in my .bashrc
echo -n -e “33]0;`hostname`07
Then on each tab as I log into a different machine (It has to have that line in the .bashrc of the user/machine I’m logging into) it sets the title as I log in to the machine, so all the tabs are correct.
And to recover on logout, I put this in the .bash_logout:
prev=`who am i | sed -e “s/.*((.*))/1/”`
if test ! x$prev = x
then
echo -n -e “33]0;$prev07″
fi
alias sett=”echo -n -e “33]0;`hostname`07″
January 20, 2010 at 10:09 am, Anonymous said:
In bash, you can do this:
PS1=”33]0;H07h:W u$ ”
The PS1 prompt gets printed at every command (see ‘man bash’). Thus, the window title gets set at each display of the prompt — so if you log out of one shell, the prompt from the old shell is displayed and re-sets the window title.
This method also gets you all the bash prompt expansions (see ‘man bash’, search for PROMPTING), like H which expands to the full hostname and h which expands to the hostname up to the first . and so on.
February 09, 2011 at 7:31 pm, Ivan Tumanov said:
This works in an interesting way –
export PS1=”$(echo -n -e “33]0;w07″)w $”
executes the echo command to set the tab title to w and then shows a regular w $ prompt.
November 07, 2011 at 11:57 am, Julie said:
Awesome. Perfect. Thanks!
November 13, 2011 at 5:36 am, Pedro Furlanetto said:
I found this one to be the most convenient:
export PS1=”\$(echo -n -e ’33]0;\W07′)\W \u $ “
November 30, 2011 at 9:47 pm, moonpixel said:
nice, using it like this
#!/usr/bin/env bash
echo -n -e “33]0;$107″
exit 0