Menu Chiudi

Colored prompt on bash console

Prompt colorato per bash

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).

Here is how to change the color prompt your terminal using bash.

# set our custom prompt yellow to assign to a limited user
dpm@kiowax:~[4]$ 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 changed 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 🙂


Leggi anche:   Implementare Port Knocking in un server Linux


Questa pagina potrebbe contenere link di affiliazione. Gli acquisti o gli ordini che effettuerai tramite tali link possono generare commissioni che ci aiutano a sostenere questo sito web.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.

Moderazione dei commenti attiva. Il tuo commento non apparirà immediatamente.

Scroll to top button