Recently I got bored with the standard prompts and colors of the Bash shell in Linux, and decided to tweak them a bit. What I decided to do was to make the root user account have a red prompt, mainly so I wouldn’t forget to log out once I was done and also to distinguish it from normal user accounts.
Editing the Bash Prompt
In order to change the color of the bash prompt, you need to edit the PS1 environment variable. You can do this by typing the following in the bash shell:
export PS1="\e[31;1m[\u@\h \@ \W]# \e[0m"
This will temporarily change the color of the bash prompt to red, and some other parts of the prompt as well.
Here is a basic breakdown of each part of the command:
The export PS1= is telling the shell that you are changing the PS1 variable
The \e[31;1m controls what foreground and background the prompt will have. 31 = Red foreground, 1 = black background.
The "[\u@\h \@ \W]#" means “your username”@”hostname” “localtime” “working directory”.
Making PS1 Environment Variable changes Permanent
If you want to make the changes permanent, you will have to append this line of code to the end of your “.bashrc” file in your home directory. You can do this with by editing the .bashrc file with any text editor in linux (nano, vi, vim, gedit) and manually add in the following line export PS1="\e[31;1m[\u@\h \@ \W]# \e[0m" or this way:
1. Put export PS1="\e[31;1m[\u@\h \@ \W]# \e[0m" into a text file called "filenamehere"
2. Then type the following command:
cat filenamehere >> ~.bashrc
3. Then type exit in the terminal
4. Open up a new terminal and you then should see the changes to the bash prompt.
This effectively uses cat to pint the export PS1 command to standard output in the shell, then with the append operator ">>" it will redirect the export PS1 command and add it to the end of the .bashrc file. It's a fun and simple shell script!
CAUTION!! Make sure you use the append operator ">>" and NOT the redirection ">" operator which will delete everything in the .bashrc file and replace it with what ever you redirected.
Reverse changes to PS1 Environment Variable
If you ever want to reverse the changes you have made to your PS1 environment variable, do the following:
1. Open a new terminal window
2. Type "vim .bashrc"
3. Use the arrow keys on the keyboard to scroll down to where it has the "Export PS1=" line.
4. Press the letter "d" twice on the keyboard to delete the whole line.
5. Press escape
6. press ":"
7. after the colon, type "qw" for quit and write. This will quit vim and save the file.
8. Exit the terminal
9. The next time you open a terminal for that user, you will have the default PS1 settings again.
If you would like to get more details and info about editing PS1 environment variables, visit the site in the references section below. It has a wealth of info on the subject. Enjoy!!
References:
http://www.funtoo.org/en/articles/linux/tips/prompt/







