I discovered through this answer that I've been setting terminal colours in my prompt in a naive way for years.

I've now modified my .bashrc to use 'tput' commands to colourise various elements of my prompt. The one remaining escape code I have is this:

TITLEBAR="\[\033]2; PROD - \u@\h:\w \007\]"

Does anyone know if there is a tput/terminfo attribute I can use to set the title bar of my terminal window, so that I can eliminate that escape?

4 Answers 4


The actual capabilities are tsl (To Status Line) and fsl (From Status Line), but of course not all terminals have then. In Linux in particular you need to set your terminal to xterm+sl or something similar.

You can test this with

export TERM=xterm+sl
echo `tput tsl` Hello world `tput fsl`; sleep 10

I wouldn't bother and keep those escapes in .bashrc

  • 2
    Seems my copy of Ubuntu lacks that terminal info. :( I blame incomplete terminfo files :) Jun 11, 2009 at 12:16
  • 1
    screen, however, appaears to support them just fine. Thanks! Jun 11, 2009 at 12:26
  • 3
    \033]; is the escape sequence in xterm for an "Operating System Command". I don't know how to do that in tput, but if it is possible to do via tput that would be a better method for cross platform terminal title setting. E.g. on xterm, it would result in the sequence \033]0;Title\007. See also here
    – Wyatt Ward
    Mar 23, 2018 at 17:09
  • @codehead Your solution is embarrassing because if I type export TERM=xterm+sl, then I no longer have syntax highting in vim.
    – SebMa
    Apr 26, 2019 at 13:49
  • 1
    Note that TERM=xterm+sl tput tsl will use the sequence \e]0; which sets both the window title and the icon name, and is probably not what you want. TERM=xterm+sl-alt, if you have such terminfo, will properly use \e]2; instead, which sets the title only.
    – MestreLion
    Nov 26, 2021 at 15:18

I can't comment, thus an extra answer:

If you use tsl/fsl, be sure to ask the terminal for hs first. hs should be true if tsl/fsl (and other *sl) are supported.

tput hs && { echo ....; }
  • 1
    +1 if you have a reference for this.
    – l0b0
    Mar 21, 2012 at 8:28
  • @l0b0 - I guess it could be inferred from man 5 terminfo, specifically the Status Lines section. See: man7.org/linux/man-pages/man5/terminfo.5.html Of course, I guess you could also do: tput tsl && { echo 'hello world'; tput fsl; }
    – mpb
    Jun 20, 2020 at 23:37
  • @mpb tput tsl and tput hs both fail in GNOME Terminal, so I'm not sure what to do with either.
    – l0b0
    Jun 21, 2020 at 2:47
  • @l0b0 - It does seem that multiple terminals do support changing the title, but this feature is not published in their terminfo entries. If you are programming conservatively, and you are writing an app that may be used across multiple terminals by third-party users, then the safe thing to do would be to check that tsl (or hs) existed. If you assume it exists, and it does not, then you would end up writing unintended text at the cursor location.
    – mpb
    Jun 21, 2020 at 5:29

Having looked at the xterm terminfo file, I can't find any code that is identical to this command, so I suspect there is not.

If you're interested, the terminfo man page lists all the commands that termcap and terminfo understand. I decompiled the terminfo database file using:

# infocmp -L xterm 

For more info on xterm's "vt100 mode" special features, see the Xterm Control Sequences document in the Operating System Controls section for all the gory details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .