Score:2

How do I change the color of the prompt in Ubuntu terminal after using sudo su?

pe flag

I want to change the color of the root prompt after using sudo su. It is currently white. I am using Ubuntu in a VirtualBox VM.

Here is a picture of my terminal:

screenshot of Ubuntu terminal in VirtualBox

Artur Meinild avatar
vn flag
Does this answer your question? [Is it possible to color the prompt in Bash?](https://askubuntu.com/questions/13892/is-it-possible-to-color-the-prompt-in-bash)
vanadium avatar
cn flag
@ArturMeinild there is nothing relevant on changing the color of the terminal in the very old question you marked as a duplicate
Artur Meinild avatar
vn flag
You don't think `force_color_prompt=yes` for root is an answer to the OP's question? If not, then it's not possible to understand what the OP is actually asking.
muru avatar
us flag
Does this answer your question? [Changing behavior of bash prompt when functioning as root](https://askubuntu.com/questions/305052/changing-behavior-of-bash-prompt-when-functioning-as-root)
vanadium avatar
cn flag
@ArturMeinild seems clear to me: make it a different color. There is even a picture.
vanadium avatar
cn flag
Does this answer your question? [Changing colors for user, host, directory information in terminal command prompt](https://askubuntu.com/questions/123268/changing-colors-for-user-host-directory-information-in-terminal-command-prompt)
Score:2
cn flag

The prompt is defined by the PS1 variable. You can see how it is defined with

~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

In standard Ubuntu, it is actually being defined with the command:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  • Change 01;32 in the part \[\033[01;32m\] to a different number to change the color of the username@hostname part.
  • Change 01;34 in the part \[\033[01;34m\] to change the color of the folder name.

A list of color codes (adapted from source):

Color       Code
Black       0;30
Red         0;31
Green       0;32
Brown       0;33
Blue        0;34
Magenta     0;35
Cyan        0;36
White       0;37

Replace 0 with 1 to get a light colored version.

This variable is set in your .bashrc configuration file, which is executed each time an interactive shell is opened. Thus, modify the existing command accordingly.

You can change the color of the prompt of the root user in the same way by editing the .bashrc file of the root user, /root/.bashrc. However, to enable a colored prompt for that account, you should also uncomment the line force_color_prompt=yes.

Score:0
ng flag

This solution is relatively simple, type

nano ~/.bashrc

in the terminal as root. I like to use nano, you may use whatever text editor you wish. Find and uncomment:

#force_color_prompt=yes

in the file, save/write out the file, then pull up a fresh terminal and enter root. You should now have colored root terminal text.

vanadium avatar
cn flag
Very likely, the OP will want a *different* color than normal users.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.