5

enter image description here

I've been reading about this topis here and tried the solution given to change the terminal name (refer to the picture on item number 1)

But none of them can change the terminal's name (item number 1).

user@linux:~$ gnome-terminal --title="SOME TITLE HERE"
user@linux:~$ 

user@linux:~$ PROMPT_COMMAND='echo -ne "\033]0;SOME TITLE HERE\007"'
user@linux:~$ 

user@linux:~$ echo -ne "\033]0;SOME TITLE HERE\007"
user@linux:~$ 

I know that item number 2 can be changed with PS1. But the title (item number 1) still didn't change even after I change the PS1

user@linux:~$ is fine. I don't want to change this, I just want to rename the terminal's title on the top (item number 1)

Sabrina
  • 2,003
  • 5
  • 24
  • 28
  • I switched to another terminal because of no good way to set the terminal title. Using PS1 hacks it sometimes changes and sometimes doesn't. And usually PS1 shows where I am and the title should show the use of the terminal (what I want to do there). tl;dr bad decision to remove this functionality for quite some people. Look for alternatives if you rely on that feature like me. – Enno Gröper Jun 23 '19 at 06:48

2 Answers2

3

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)

cmak.fr
  • 8,696
  • Limitation: when a program changes the PS1, the title may change too (example: ssh to another host will reset the custom title) – cmak.fr Jun 24 '19 at 04:36
2

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?