How to Change Bash Custom Prompt (PS1)
-
Linux
CommandLine
CommandOfTheDay
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\` "
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
- By using http://bashrcgenerator.com/ you can generate your prompt easily.
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.