Wednesday, May 30, 2012

Painting /etc/motd with some colour

Adding colours to foreground and background of the /etc/motd is a useful way to hightlight remarks or message that users can take a note. It is not very difficult. Firstly, do take a look at the colour codes.

^[[0m    - Reset the terminal characteristics
^[[1m    - emphasis (bold)

^[[30m    - Foreground black
^[[31m    - Foreground red
^[[32m    - Foreground green
^[[33m    - Foreground yellow
^[[34m    - Foreground blue
^[[35m    - Foreground magenta
^[[36m    - Foreground cyan
^[[37m    - Foreground white

^[[40m    - Background black
^[[41m    - Background red
^[[42m    - Background green
^[[43m    - Background yellow
^[[44m    - Background blue
^[[45m    - Background magenta
^[[46m    - Background cyan
^[[47m    - Background white

The ^[ can be achieved by pressing CTRL-ESC then ESC. Do note that CTRL-ESC then ESC is not the same as directly typing ^[

The steps are as followed
  1. CTRL-ESC then ESC and type "[31m" (without the quotation)
  2. The Message you wish to convey
  3. Terminating the with CTRL-ESC then ESC and type "[[0m"
For example,

^[[31m #########Hello I'm foreground red############  ^[[0m

No comments: