Colored prompt on bash console

It can be nice to have different color  prompt on the terminal screen to differentiate different login. the following code simply set up PS1 to have yellow prompt on the terminal screen, which can be appended in your ~/.bashrc or file ~/.bash_profile, depending on your configuration (actually it depends on the distribution, the user, and so on).

the following lines of code can be freely sed and redistributed, in the hope that

they are useful for anyone.

# set our custom prompt yellow to assign to a limited user
dpm@kiowax:~[6]$ PS1='\[\e[33;1m\]\u@\[\e[33;1m\]\h:\W[\#]% \[\e[0m\]'
# set our custom prompt  light blue to assign to a regular user
dpm@kiowax:~[7]% PS1='\[\e[34;1m\]\u@\[\e[34;1m\]\h:\W[\#]$ \[\e[0m\]'
# set our custom prompt light green to assign to a another regular user
dpm@kiowax:~[8]$ PS1='\[\e[32;1m\]\u@\[\e[32;1m\]\h:\W[\#]$ \[\e[0m\]'
# set our custom red prompt to visually and uniquely identifies root
dpm@kiowax:~[9]$ PS1='\[\e[31;1m\]\u@\[\e[31;1m\]\h:\W[\#]# \[\e[0m\]'

Please note that, in the above examples, I've also chenged the last part of the prompt with character '%', '$' and '#' respectively. This can be sometime useful to differentiate environments (ksh, bash, sh, etc.).

Also the prompts above have the '\#' which include the command number in the prompt, which is another important information concerning the right sequence of the command entered so far. Of course, if you don't like it, you can simply remove those two characters from PS1 string.

That's all folks :)


Lascia un commento

Tutti i commenti dovranno essere verificati ed approvati dal webmaster, prima di essere pubblicati


Quote of the Day

Chiunque rimanga turbato dalla teoria dei quanti, non può averla capita.

Niels Bohr

Chi è online

Abbiamo 355 visitatori e nessun utente online


Per essere sempre aggiornato sulle ultime novità del sito.
Go to top