Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have several instances of terminals running in my working environment, what I would like is to set a specific title for each one, in order to have a clear idea what purpose the specific terminal serves i.e. Apache, editing_ini, postgres etc...

Of course from the command line.

share|improve this question
    
Further to Ward's comment: Don't forget to "unset PROMPT_COMMAND" before you send the title-change escape sequence, otherwise any change you make will be lost as soon as the next shell prompt. –  Jon Green Sep 2 '11 at 11:38
    
For a similar question for KDE, see stackoverflow.com/questions/8782159/… –  naught101 May 29 '12 at 2:22
    
I had this issue when switching from OS X to Ubuntu. To obtain custom titles within a multi-tab set-up, I used gnome-terminal --load-config together with this script I've written. –  halfer Apr 13 at 1:29

10 Answers 10

up vote 50 down vote accepted
  • The most userfriendly way is picking it from the menu Terminal -> "Set Title...".

  • There are other ways however, you can also issue

    gnome-terminal --title="SOME TITLE HERE"
    

    This might not give the desired effect since there is a big chance that your .bashrc overwrites that behaviour.

  • Bringing us to the last method, which I shamelessly ripped out of my .bashrc.

    PROMPT_COMMAND='echo -ne "\033]0;SOME TITLE HERE\007"'
    

As an extra reference, this is the particular line in my .bashrc

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'

You may also need to comment this code out in your ~/.bashrc

case "$TERM" in
xterm*|rxvt*)
    # JEFFYEE REMOVED because it makes commands to title() not work
    #PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac
share|improve this answer
    
Need to comment out or remove as you mentioned in order to take effect! –  topless Jan 20 '11 at 15:49
    
@Chris What exactly needs to be commented out? –  Alvin Row Jan 22 '11 at 19:49
    
@DoR the code PROMPT_COMMAND=... I commented it out. If not removed from the .bashrc then the title remains the same since its getting override by the .bashrc settings. –  topless Jan 24 '11 at 10:32
    
@Chris I didn't see any PROMPT_COMMAND in my ~/.bashrc, but I had to comment out this section. –  Alvin Row Jan 26 '11 at 17:48
    
@DoR That seems odd given PS1 is the variable for the actual prompt. Hmm, that makes me wonder why the one for the title gets called PROMPT_COMMAND. Anyone know anything about that? –  Ward Muylaert Jan 26 '11 at 22:24

If you use the Vim editor, you can also enable this option in your vimrc:

:set title

which is disabled by default. It will set cool terminal titles showing the filename which you are editing at the moment and some other things.

share|improve this answer

For the sake of completeness, I would add that you can also set the gnome-terminal title using this command:

wmctrl -r :ACTIVE: -N "MyWindowTitle"

You'll need to install the package wmctrl Install wmctrl first.

share|improve this answer

Ward's answer is great if you want to set your title based on what host you're on etc every time you open a terminal. If you just want to quickly set a title though, you can just run echo by itself:

echo -ne "\033]0;SOME TITLE HERE\007"

or make a simple bash script, say termtitle

#!/bin/bash

echo -ne "\033]0;${1}\007"

which you can run with termtitle "some title here"

share|improve this answer

@Ward I think you need to recheck as even I came across what @sladen commented. I searched some more and was able to find help on ubuntuforums

What I did:

edit .bashrc and put the following function

function title {
    echo -en "\033]2;$1\007"
}

Also comment out PS1

#PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Now open a new terminal and type the following:

title "MyTitle"

Where "MyTitle" is your title of choice.

I see that the commands are same but with PROMPT_COMMAND, I was seeing the output as a message on the terminal rather than terminal title.

P.S. was not able to add a comment to Ward's answer which should have been the right place for this post. Nevertheless adding as a new answer.

share|improve this answer
    
most concise and correct answer. –  Nishant May 7 '13 at 4:50
    
This is not working. –  kapad Jul 29 '13 at 14:16

Argh, so many answers...

I tried wmctrl, which almost worked, except I couldnt get it to change the icon title, at least not permanently.

The solution is that PS1 in ubuntu sets the title.

The default PS1 is

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 

... which sets the title in the first escape sequence.

Thus, there are two solutions:

Solution 1: simplify PS1, then use PROMPT_COMMAND

Change PS1 to something simpler:

PS1="\u@\h:\w\$ "

... then use the PROMPT_COMMAND:

PROMPT_COMMAND='echo -ne "\033]0;SOME TITLE HERE\007"'

Solution 2: directly modify PS1

Simply modify PS1 with new title:

PS1='\[\e]0;newtitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
share|improve this answer

If you are a Ubuntu user, you can change the title of a gnome-terminal tab using the HUD.

While in the gnome-terminal, hit Alt to bring up the HUD, type the first few letters, e.g. "tit", hit enter and type in your new title.

This is a very quick method and avoids using the mouse.

share|improve this answer
    
Indeed. Keeps the hands on the keyboard. The existing title is displayed, so it's fast and easy to also just modify the existing one using this method. –  Rubistro Dec 19 '13 at 0:39

There is a menu item "Terminal -> Set title".

You could need also to set "Do not modify title" in terminal profile preferences.

share|improve this answer
    
The question wants a command line solution –  kapad Jul 29 '13 at 14:16

Another way of changing the title of gnome-terminal is by using gconftool-2; this changes the initial terminal title for the profile selected, so you could have different profiles associated with titles such as 'Apache', 'Editing', etc. You would then launch gnome-terminal with the appropriate profile to get the terminal title you had specified. This is in contrast to gnome-terminal --title "name" which changes the title per terminal, but doesn't affect the initial title specified in the profile.

You could use the following command in a script to set the name of the terminal for a profile, and you could have the name of the terminal change at certain times in the day to remind you of things:

gconftool-2 --set /apps/gnome-terminal/profiles/Default/title --type=string "Apache"

This is for the default profile, but you could set the title for other profiles as well by changing, for example, Default to another profile like Profile0:

gconftool-2 --set /apps/gnome-terminal/profiles/Profile0/title --type=string "Editing"

I thought this way of changing the title is of use because of the way it could be used in scripting, or just as a quick command-line way to set the title for the profile. Note that sometimes you have to relaunch the terminal with the specified profile for the gconftool-2 setting to take affect. The complete settings available for gnome-terminal can be listed with gconftool-2 -R /apps/gnome-terminal.

share|improve this answer

To display only the current working directory in the title, try this in your '.bashrc' :

PROMPT_COMMAND='echo -ne "\033]0; ${PWD##*/}\007"'

or

PROMPT_COMMAND='echo -ne "\033]0;$(basename ${PWD})\007"' 
share|improve this answer

Your Answer

 
discard

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.