I am wanting to know how I can display the TTY a terminal is currently using in the window name of the Terminal. I don't see any options in Terminal Preferences to display such thing on the Terminal window name with gnome-terminal.

I ask this because I was using Terminal on Mac OS X and I could set in the preferences to display what TTY the terminal is currently using, and just wondering how I could do the same for gnome-terminal, and yes I do know that Terminal on both Mac and Linux are completely different, yet they share the same UNIX command line stuff.

Is there something I could add to .bashrc or .profile to append this to the window name of Terminal? or perhaps something I could add to dconf to make this a custom option?

I do know that typing tty is an option or ps -a to display that, but that only displays inside the terminal window output, but in the window name I'd like it to show all the time and for every new window or tab that opens ie; /dev/tty/1, /dev/tty/2, /dev/tty/3 etc… appended to the Window title like these for example.

Terminal | tty/1
Terminal, tty/2

You can modify your .bashrc as follow:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PS1="\[\e]0;$(tty | cut -d/ -f3,4) | ${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Now new gnome-terminal will look like this:

enter image description here

Note that gnome-terminal uses Pseudo-Terminals, see What does "pts/" in the output of w mean?

  • Thanks this is really useful. If I were to change this so that the TTY displays after the user@host: ~ part would I be able to just swap around that first part to display on the end after $PS1 or would I have to do something more to make this work correctly? – user94959 Oct 24 '14 at 10:10
  • 2
    @user94959 use PS1="\[\e]0; ${debian_... \w\a | $(tty | cut -d/ -f3,4)\]$PS1. That is, leave the final $PS1 at the end, always. – muru Oct 24 '14 at 10:15

Set a PROMPT_COMMAND in your ~/.bashrc like so:

PROMPT_COMMAND='echo -ne "\033]0;$(tty | sed s:/dev/::)\007"'

Note that this title may be overwritten by other things, such as your prompt (PS1), so be sure to check at least PS1 if your title is not being set.


  • This is nice, but it just replaces the whole instance of the title with just the TTY it's using. – user94959 Oct 24 '14 at 10:11
  • @user94959 I know. The title is usually set in PS1, as Sylvain's answer shows, which is why his answer adds and not replaces. – muru Oct 24 '14 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy