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

How can I arbitrarily change the title of a Terminal window in Mac OS X? I have seen this question and this magicwrap thing, but think it's just a simple Mac OS X command.

share|improve this question
Should note that there's nothing OS X specific about this -- the answer will work on pretty much any terminal. – Andrew Aylett Feb 6 '10 at 11:22
Is it Bash-specific then? – Dan Rosenstark Feb 6 '10 at 14:55
@Andrew Aylett, so the script I put in my answer (below) will work on the linux distros, too? – Dan Rosenstark Feb 6 '10 at 18:20
Yes, it should work anywhere (with an sh-derived shell) that uses unix-y terminals. – Andrew Aylett Feb 11 '10 at 22:02
up vote 35 down vote accepted

This article tells you how.

Essentially, you use character sequences echoed to the screen to inform the terminal of what title it should display.

title='My first title'
echo -n -e "\033]0;$title\007"

In the above example, whatever the variable title is set to while become the terminal's title. Of course, you could just have the title in the string to echo such as:

echo -n -e "\033]0;My first title\007"

But the first way makes it a slightly bit easier to use and/or extend later.

share|improve this answer
Excellent. Could you include a sample script (like this? echo -n -e "\033]0;$1\007") in your answer so I can mark it best answer, please? – Dan Rosenstark Feb 6 '10 at 9:15
printf may be more reliable: printf "\033]0;%s\007" "$title_variable" (the various options and behaviors of echo are not the same across all systems, shells, or even shell options) Also, variable assignments in bash should not have spaces around the equals sign. – Chris Johnsen Feb 6 '10 at 12:03
I used $* and within a function, so I wouldn't have to quote my title string. – BeepDog Jul 1 '15 at 21:39
Is there a way to change the title from within a C program? The program I'm thinking about is running animation based on ncurses.h so I am not sure how to echo to the terminal :-( – phs Nov 2 '15 at 17:23
OK: Just fprintf(stdout,..) works. I should have tried before asking. – phs Nov 3 '15 at 6:52

Adding the following to your ~/.profile will achieve the same effect:

# function for setting terminal titles in OSX
function title {
  printf "\033]0;%s\007" "$1"

And then a quick title 'et voila' will sort all your tabs out.

share|improve this answer
why is it a problem if you have many functions in .profile? is there a limit? – tgkprog Jun 4 '13 at 14:22
IDK why, but had to edit .bash_profile instead of .profile – Nakilon Sep 8 '13 at 23:45
Or: alias title="printf '\033]0;%s\007'". – kenorb May 14 '15 at 12:40

Remix of Dan MgG's answer:

echo -n -e "\033]0;$1\007"

Store it in a file called /usr/bin/title (using sudo!) and chmod it to +x. Then from anywhere you can just type

title 'Trying to Figure This GIT Thing Out'

and you get a nice little title.

(Syntax may vary if you're not on OSX, if I understand correctly)

share|improve this answer

Thanks for this. I just added a function to my .bashrc:

    function stit() {
    echo -n -e "\033]0;$1\007"

In my mind "stit" = a convenient shortcut for "set_title". And now when I want to set the title of my windows on the fly, I type:

stit "[new window title]"
share|improve this answer

As an alternative to sh-based command line solutions, the OS X Terminal app has a preference to change the title as follows: Under the Terminal->shell menu there is a "edit title" choice, select that and you can change the title easily.

share|improve this answer
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review – Ramhound Mar 21 at 16:52
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Ƭᴇcʜιᴇ007 Mar 22 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .