How to change Gnome-Terminal title?
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.
616 Answers
Alternatives:
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
.bashrcoverwrites 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 16 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 function (inside your ~/.bashrc), say termtitle
termtitle() { printf "\033]0;$*\007"; }which you can run with termtitle some title here.
If you use the Vim editor, you can also enable this option in your vimrc:
:set titlewhich is disabled by default. It will set cool terminal titles showing the filename which you are editing at the moment and some other things.
1Argh, so many answers...
I tried wmctrl, which almost worked, except I couldn't get it to change the icon title, at least not permanently.
The problem is that the PS1 in Bash 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: \e]0;\u@\h: \w\a
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\$ 'Notes on escape codes
Note that (borrowing from wjandrea's comment below this answer):
\eor\033is the escape (ESC) character, which starts an escape sequence.]starts an operating system command (OSC).- For an xterm,
0;means "set the title", and \aor\007is the bell (BEL) character that terminates the OSC.
More info:
7For 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 first.
Works on Ubuntu 16.04 to 20.04
This answer is simpler than most others. To use it, you would simply type:
title "My new title"
- Easier to remember than most other answers.
- The accepted answer and others do not work on modern versions of Ubuntu (from 16.04 on up).
- This answer doesn't require 3rd party packages like
wmctrlandxdotool. - Version 2 allows running multiple times in the same session.
One-time function creation
Create the title function in your ~/.bashrc file:
function title() { # Set terminal tab title. Usage: title "new tab name" prefix=${PS1%%\\a*} # Everything before: \a search=${prefix##*;} # Eeverything after: ; esearch="${search//\\/\\\\}" # Change \ to \\ in old title PS1="${PS1/$esearch/$@}" # Search and replace old with new
}Save the ~ /.bashrc file. After opening a new terminal tab use:
title "Special Projects"or:
title Special\ ProjectsA phrase with spaces must be wrapped in double quotes (") or each space must be escaped with \.
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.
(UPDATE: In newer versions of gnome-terminal, this was removed. Try other answers.)
5Another 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.
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"' Another solution is to use xdotool to simulate keystrokes, maybe useful in scripts:
Set a keyboard shortcut in gnome-terminal:
Edit > Keyboard Shortcuts... > Terminal > Set TitleFor example assing the
Shift+Ctrl+Y.Install
xdotoolif you don't have it already:sudo apt-get install xdotoolThe following sequence of commands (that you can use also in a bash script) will set the terminal/tab title (escape the spaces with
\):xdotool key ctrl+shift+y xdotool type My\ new\ fabulous\ title xdotool key Return[optional] You can also use xdotool to e.g. open a new tab and set the title with the above commands, using:
xdotool key ctrl+shift+tConsider adding a sleep time before and after opening a new tab, e.g.
sleep 1(to wait for 1 second).
This is not the most elegant solution, but it worked for me! The previous answers did not work in my case. I use gnome-terminal in Ubuntu 14.04 and I wanted to make a bash script.
This worked in my Gnome Terminal 3.18.3.
Edit your .bashrc file and add this function
# Update gnome terminal title
function termtitle() { # take argument TITLE=$1 shift # update title PROMPT_COMMAND='echo -ne "\033]0; $TITLE \007"'
}Don't forget to source your .bashrc file
$ source ~/.bashrcAnd then you can simply update you'll be able to change terminal title like this:
$ termtitle "MariaDB CLI" 2 As an addition to other valid answers, xdotool has the functionality that allows you to change the title of any application and window.
xdotool getactivewindow set_window --name "WINDOW NAME HERE"Note that the change won't be permanent, it'll change when you change directory and probably be set to your PWD.
To permanently change it, you can modify PS1 variable within ~/.bashrc as mentioned.
PS1="${PS1}\[\e]0;New Title\a\]"This modification is permanent. In fact after this, the changes you make with xdotool will also be permanent and won't change with cd.
for a wsl (windows subsystem for linux) terminal tab i'll do this:
# function to set terminal title
function set-title(){ if [[ -z "$ORIG" ]]; then ORIG="$PS1" fi TITLE="\[\e]2;$*\a\]" PS1="${ORIG}${TITLE}"
} In case any poor souls like myself are forced to use tcsh, try something like this in your .cshrc:
set prompt='%{\033]0;%n@%m\007%}%~%# 'Source and more details:
2easy Ubuntu 20.04 way (*from )
PS1=$PS1"[\e]0;New_Terminal_Name\a]"
If you are using gnome 3, the convenient Terminal > Set Title menu option has been removed. You can install a gnome 2 forked terminal which still has that "Set Title" menu option, and run that instead:
sudo apt-get install mate-terminalInstead of running "Terminal", run "MATE Terminal". You should probably also select mate-terminal in sudo update-alternatives --config x-terminal-emulator.
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"