• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to customize and change color of the bash login prompt in Linux

    There are various method we can use to customize and change the colour of the login prompt of your bash shell in Linux.

    Follow below link to customize or change the view of the login prompt



    Below are some of the colour codes
    Black           -> 30
    Red            -> 31
    Green           -> 32
    Yellow         -> 33
    Blue           -> 34
    Magenta         -> 35
    Cyan            -> 36
    White           -> 37
    Bright Black    -> 90
    Bright Red      -> 91
    Bright Green    -> 92
    Bright Yellow  -> 93
    Bright Blue     -> 94
    Bright Magenta -> 95
    Bright Cyan     -> 96
    Bright White    -> 97

    Octal Method
    start   -> \033[0m
    end     -> \033[m

    Bash Method
    start   -> \e
    end     -> \e[m

    IMPORTANT NOTE: Additional escape characters must be added for PS1 variable so that bash can interpret them correctly, without which you may face problem while searching for history or running history based commands using 'ctrl +r'
    Below additional prompt must be added additionally
    start   -> \[
    end     -> \]


    Using Octal Format

    My login prompt
    [root@golinuxhub ~]#

    Change the color of the prompt to 'RED'
    # export PS1='\[\033[31m\][\u@\h ~]# \[\033[m\]'


    Below image shows complete list of color codes

    Similarly you can modify the command to change the prompt to different colors, you only need to care about below format while using the above command
    start   -> \[\033[31m\]  <-- Here modify '31m' with the color number
    end     -> \[\033[m\]    <-- to reset the terminal or else your commands would also appear with the same color






    Using Bash Format

    My login prompt
    [root@golinuxhub ~]#

    Change the color of the prompt to 'YELLOW'
    # export PS1='\[\e[33m\][\u@\h]#\[\e[m\] '


    Change the color of the prompt to "BRIGHT WHITE"
    # export PS1='\[\e[97m\][\u@\h]#\[\e[m\] '


    Below image shows complete list of color codes

    Similarly you can modify the command to change the prompt to different colors, you only need to care about below format while using the above command
    start   -> \[\e[33m\]  <-- Here modify '31m' with the color number
    end     -> \[\e[m\]    <-- to reset the terminal or else your commands would also appear with the same color

    I hope the article was useful.

    Deepak Prasad

    Deepak Prasad is an anonymous techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+

    Do you also have something to share here?

    Become an author and be a part of our GoLinuxHub Team, Click here for more information
    How to customize and change color of the bash login prompt in Linux How to customize and change color of the bash login prompt in Linux Reviewed by Deepak Prasad on Sunday, February 11, 2018 Rating: 5

    No comments:

    Powered by Blogger.