I've searched for a way to change terminal title and found this bash command:

echo -ne "\033]0;NEW_TITLE\007"

It works as it have to, but i'm now interested in what this "magic symbols" mean and how it works.

  • It shows nothing for me on Bash. – Gqqnbig May 13 '19 at 1:20

That uses an XTerm control sequence. echo with -e interprets certain sequences in the string given, in this case \033 became Esc, and \007 is the ASCII bell character (see man 7 ascii).

An Esc (represented as ^]) followed by ] is, in XTerm parlance, an Operating System Control code. Terminals which support it interpret it as given in the above link:

OSC Ps ; Pt ST
          Set Text Parameters.  For colors and font, if Pt is a "?", the
          control sequence elicits a response which consists of the con-
          trol sequence which would set the corresponding value.  The
          dtterm control sequences allow you to determine the icon name
          and window title.
            Ps = 0  -> Change Icon Name and Window Title to Pt.
            Ps = 1  -> Change Icon Name to Pt.
            Ps = 2  -> Change Window Title to Pt.

OSC being ^]], the Ps in this case is 0, which sets Pt, in this case NEW_TITLE, as the terminal title.


| improve this answer | |

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.