I am wondering if there is a way to set the terminal window title bar to the current UTC time, probably without seconds (too much flashing). I do a lot of cloud work and looking to minimize thinking about the math of subtraction :)

Most of the things I have found is for the current path, I am just not sure how to update the title bar when it changes in the terminal for the time.

  • Close, but not quite: askubuntu.com/questions/360063/…
    – muru
    Feb 3, 2017 at 1:21
  • Just wondering, what's wrong with having a regular clock (e.g. on your desktop's panel in the corner, or a standalone clock app) independently of terminals?
    – egmont
    Feb 3, 2017 at 13:02
  • The regular clock shows my local time zone. I would also like to have the UTC time displayed. It just helps since a lot of the dev work I do is cloud based and I end up translating between the two. Throw in difference between daylight savings between countries.... Just a small little assist Feb 5, 2017 at 20:48

2 Answers 2


As far as I understand, you'd expect the title to always update regularly, no matter what happens inside the terminal; that is, even if there's no activity (e.g. the prompt is displayed and you're not typing anything), or when a long process is running. Am I right?

The title can be updated by emitting a certain escape sequence called OSC 0, e.g.

echo -ne '\e]0;newtitle\a'

If you don't see this command changing the title, that's because the subsequent prompt overrides it again. You need to remove the setting of the title from the prompt. As a proof of concept, you can try this to make sure it indeed sets the title:

echo -ne '\e]0;newtitle\a'; sleep 5

You could write a script that emits and regularly updates the title in a similar manner, and run that script in the background.

There's one inherent problem with this approach, though. If you're running another app in the terminal, that application might also print escape sequences. Especially with other layers in between, such as ssh, there's a slim chance that the given app prints an escape sequence in two consecutive steps (e.g. the escape sequence that switches the foreground to red is "\e[31m" which might be printed as the characters "\e[3" in a single step, and shortly afterwards "1m"). There's a slight chance that your background script will intervene and print its stuff in the middle, potentially breaking the display big time (no pun intended).

There's no simple way to prevent this from happening. Perhaps tmux or a similar layer can be configured to update the title to contain the time. I don't know if let's say tmux supports this, but it has the knowledge required to make sure that this small chance of display corruption is eliminated. Well, it already shows the time by default (not in the title but on the actual canvas, though).

I recommend that you run a single graphical clock applet or app somewhere on your desktop, independently of terminal emulators. That way the same piece of information (the time) is not displayed in multiple locations, only at one place. Furthermore, you save the terminal's title (the available real estate) for some actual more meaningful information that's specific to that particular terminal.

  • Thanks. I have the time displayed, but it is local and not UTC. May want to find a way to display a second time. Feb 4, 2017 at 20:00

I haven't testet this, but bash has $PROMPT_COMMAND that should be executed before showing the prompt.

If you put

PROMPT_COMMAND="echo -ne '\e]0;$(date)\a'"

in your .bashrc, the date will be set as title, and updated every time the prompt is displayed.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.