Gnome: Change title of current terminal from bash command line

9

1

I know there are options to start a new terminal with a specified title, and that is is possible to change the title from a terminal using the menu: 'Terminal' -> Set Title.

However, I want to change it for a current terminal from command line. How can I change the title for an existing Gnome terminal from command line?

Sander

Posted 2012-03-12T12:44:09.027

Reputation: 303

Answers

13

Output a suitable xterm escape sequence.

echo -ne '\033]0;New title\007'

See also How to change the title of an xterm.

tripleee

Posted 2012-03-12T12:44:09.027

Reputation: 2 480

@kapad Where does this no longer work? It works for me, still. – tripleee – 2015-11-11T05:24:32.377

Warning, this will not work if PS1 and/or PROMT_COMMAND variables are set (in bashrc e.g. ) to set the title. In that case, after issuing this command, bash will first execute the contents of PROMT_COMMAND, then redraw the prompt ( = the text with the $-sign) by printing PS1. Both variables have the potential to reset the title. See the link in Zach Pfeffer's answer with more details (it's not only for Ubuntu). – mxt3 – 2019-01-19T12:12:04.260

That's PROMPT_COMMAND with a P. Your comment is a bit of a sweeping generalization; but certainly, if something else is rewriting the prompt (regularly or not), it will overwrite whatever you put there. – tripleee – 2019-09-26T03:40:41.620

Perfect, thats it! :D Also, thanks for the very interesting link. – Sander – 2012-03-13T15:26:02.590

Nice, but is it cross-platform compatible? – l0b0 – 2012-03-20T15:00:04.307

http://ubuntuforums.org/archive/index.php/t-448614.html - there is a discussion regarding other terminals. I don't have many measuring points, but the xterm variete at least works for me in rxvt-unicode as well. – Daniel Andersson – 2012-03-20T15:49:04.970

@l0b0: Across which platforms? Many ssh clients on various platforms offer xterm compatibility, as do most xterm replacements. – tripleee – 2012-03-21T05:15:27.790

1

@tripleee: Usually it's recommended to use tput commands to print such escape sequences, as mentioned in this exact duplicate.

– l0b0 – 2012-03-21T08:27:03.360

@l0b0: ack; you are right, of course. – tripleee – 2012-03-21T12:28:29.600

1@triplee Thanks for the input! However I don't consider this question as an exact duplicate of the one you mentioned. The context of the other question is very different. – Sander – 2013-02-13T10:02:57.463

2This no longer seems to work – kapad – 2013-07-29T14:19:20.120

0

If you're using Ubuntu 16.04 you may need to clear the PS1 and PROMPT_COMMAND like:

PS1=$
PROMPT_COMMAND=
echo -en "\033]0;New title\a"

I put together a write up on it at link.

Zach Pfeffer

Posted 2012-03-12T12:44:09.027

Reputation: 1

0

It might be worth your while to try KDE. It has tabbed terminal windows, and each tab can be named just by right clicking on the tab.

Scott C Wilson

Posted 2012-03-12T12:44:09.027

Reputation: 2 210

Thanks for your suggestion, however, I'm still fond with Gnome :) – Sander – 2012-03-12T22:10:54.890

0

If you need to set it to the hostname where you are logged into you can use:

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

Benjamin Goodacre

Posted 2012-03-12T12:44:09.027

Reputation: 516