How to change Ubuntu's terminal name

The feature gnome-terminal --title have been removed since Gnome v3
If you want to keep Gnome Terminal and change the Window title you will have to play with PS1, see below how to do it.


The Gnome 2 terminal has been forked as mate-terminal bundled in Ubuntu Mate. The title option is still available with this version
sudo apt-get install mate-terminal
enter image description here


With Gnome Terminal, a way to set the window title will be to play with PS1
You can add a function to your .bashrc file an call it to change the Window/Tab title

nano ~/.bashrc
Add the function

function set-title() {
  if [[ -z "$ORIG" ]]; then
    ORIG=$PS1
  fi
  TITLE="\[\e]2;$*\a\]"
  PS1=${ORIG}${TITLE}
}

source ~/.bashrc to reload
set-title Some new title to change the Window/Tab title

enter image description here

Limitation: when a program changes the PS1, the title may change too (example: ssh to another host will reset the custom title)


hostnamectl set-hostname on 13.10+ desktop

This is the best way if you have systemd (13.10 onwards) and if cloud-init is not active (see below):

hostnamectl set-hostname 'new-hostname'

It:

  • does not require rebooting
  • persists after reboots

More info at: https://askubuntu.com/a/516898/52975

18.04 onwards: cloud-init

18.04 Introduced cloud-init which can control setting of the hostname so hostnamectl changes it won't stick after a reboot if cloud-init is installed. TODO: how to check if it is installed, is it installed by default on the desktop image or just server?

If you want hostnamectl changes to stay after a reboot, then you'll need to edit the cloud-init config files, disable cloud-init's hostname set/update module:

sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg

or disable cloud-init entirely:

sudo touch /etc/cloud/cloud-init.disabled

See also: How do I change the hostname without a restart?