How to Change Bash Custom Prompt (PS1)

Overview

  • Most of our work on shell prompt.
  • By Default, PS1 is little bit boring.
  • I’ll show you how to add useful information on your shell prompt

Alert Prompt (PS1)

  • Alert Prompt (PS1) change your shell color to RED when your previous command exit status is non zero.
[root@edytk.github.io ~]# PS1="\`if [ \$? = 0 ]; then echo \[\e[34m\]^_^[\u@\h:\w]\\$\[\e[0m\]; else echo \[\e[31m\]O_O[\u@\h:\w]\\$\[\e[0m\]; fi\` "

How to Change Bash Custom Prompt (PS1)

Display Date and Time

[root@edytk.github.io ~]# PS1='\[\033[0;32m\]┌──\[\033[0;36m\]\u@\h\[\033[0m\033[0;32m\]─┤├─ \[\033[0m\]\t \d\[\033[0;32m\] ─┤├─ \[\033[0;31m\]\w\[\033[0;32m\] ─┤ \n\[\033[0;32m\]└──▶ \$\[\033[0m\] '
┌──root@TuxLabs─┤├─ 11:18:43 Thu Jun 25 ─┤├─ ~ ─┤
└──▶ #

Generate Prompt Online

NOTE!: For more detailed information use man bash and search for PROMPTING.



Newsletter

Get updated when I create new content.
Unsubscribe whenever. Never any spam.

Note

I'm Tama. I turn down every ad, affiliate, and sponsor request I get. I write free resources that help people. If you enjoy my content, please consider supporting what I do.

Support my work