A photo of Mitesh Shah

Mitesh Shah

Linux Enthusiast
System Administrator

Email Skype Github Twitter Google+ Resume Hire Me Keybase LinkedIn Stackoverflow


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@miteshshah.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@miteshshah.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@miteshshah─┤├─ 11:18:43 Thu Jun 25 ─┤├─ ~ ─┤
└──▶ #

Generate Prompt Online

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





Post Navigation