This is what I currently have. It displays black on bright white. However, I want to have blue (0;34m) on bright white.


I used this website as a reference, but I did not manage to get it working. Any help would be greatly appreciated.

migrated from serverfault.com Apr 13 '16 at 13:45

This question came from our site for system and network administrators.

  • 1
    <Esc>[34;47mWelcome!<Esc>[m – Stéphane Chazelas Apr 13 '16 at 17:00
  • also, use ctrl-v in vi to insert esc. – Archemar Apr 13 '16 at 17:03
  • @StéphaneChazelas Thank you. It worked. Why does it work? I don't understand the logic of the codes. – Z0q Apr 14 '16 at 8:47

The /etc/motd file is data (cannot contain a script, such as "echo -e"), and is presented to all logins irregardless of their actual terminal type. While you can do this for some configurations, the usual recommendation is that /etc/motd should be plain text (no escape sequences) because:

  • attempting to print colored text does not take into account whether the user's terminal can display the escape sequences,
  • the colors do not take into account the current (or default) foreground and background colors of the terminal, and
  • do not take into account that some logins may translate nonprinting characters to "readable" form.

If you really want to do this, you should be aware that

  • getting a particular background color depends upon the terminal,
  • the text background color is not necessarily the same (or even close) to the terminal's default background color,
  • some terminals color erased areas of the screen, such as when clearing the screen, using the current "ANSI colors", while other terminals do not.

Further reading:

  • Thank you for thorough explanation and references. I cannot upvote your answer yet since I do not have enough reputation on this website. – Z0q Apr 14 '16 at 8:57
  • But you can mark it "accepted" if it is acceptable. – Thomas Dickey Apr 14 '16 at 9:02

I would advise not following those instructions. The motd is presented to all interactive logins, regardless of terminal type. This means that embedding control characters in the output is going to be wrong for at least one user, at least once.

If you feel you really must, then use tput to generate the correct codes for the user's terminal. That's much safer. For blue on white, use

tput setaf 4; tput setab 7

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.