{"id":451,"date":"2020-10-16T12:47:12","date_gmt":"2020-10-16T12:47:12","guid":{"rendered":"https:\/\/dft.wiki\/?p=451"},"modified":"2026-06-09T13:34:03","modified_gmt":"2026-06-09T17:34:03","slug":"changing-prompt-collor-on-bash-terminal","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=451","title":{"rendered":"Changing Prompt Color on Bash Terminal"},"content":{"rendered":"<p>There is no technical reason to change the color of the terminal console, but anyone can accidentally issue commands as another user or while logged in to the wrong machine when all prompts look the same.<\/p>\n<p>That is what we are going to address:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-453 size-full\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-09-21.png\" alt=\"\" width=\"674\" height=\"154\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-09-21.png 674w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-09-21-300x69.png 300w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/p>\n<p>Find out your current prompt style code:<\/p>\n<pre>echo $PS1<\/pre>\n<p>To change your prompt style, run the following command replacing the bold text with the desired style:<\/p>\n<pre>export PS1=\"<strong>put_the_new_style_here<\/strong>\"<\/pre>\n<p>Try the following two styles to see how it works:<\/p>\n<pre>export PS1=\"\\[$(tput setaf <strong>3<\/strong>)\\]\\t \\u@\\h:\\w $ \\[$(tput sgr0)\\]\"\r\nexport PS1=\"\\[$(tput setaf <strong>1<\/strong>)\\]\\t \\u@\\h:\\W $ \\[$(tput sgr0)\\]\"<\/pre>\n<p>Notice the difference between the lines. Only one number changed: 3 to 1. That is because <strong>3 means Yellow<\/strong> and <strong>1 means Red<\/strong>.<\/p>\n<p>Color codes for the <strong>tput<\/strong> command:<\/p>\n<ul>\n<li>0 = Black<\/li>\n<li>1 = Red<\/li>\n<li>2 = Green<\/li>\n<li>3 = Yellow<\/li>\n<li>4 = Blue<\/li>\n<li>5 = Magenta<\/li>\n<li>6 = Cyan<\/li>\n<li>7 = White<\/li>\n<\/ul>\n<p>This configuration is lost as soon as you close the terminal. To make it permanent, edit the file ~\/.bashrc (on Ubuntu 20.04; other systems may use .bash_profile):<\/p>\n<pre>sudo nano ~\/.bashrc<\/pre>\n<p>Append the color definition line at the end of the file.<\/p>\n<p>There are other ways to create more complex color schemes, such as changing the color of specific parts of the prompt or applying Bold or Italic:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-454 size-full\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-37-44.png\" alt=\"\" width=\"736\" height=\"118\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-37-44.png 736w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2020-10-16-08-37-44-300x48.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/p>\n<pre>export PS1='\\[\\033[01;33m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '<\/pre>\n<p>The syntax follows this structure: <strong>\\[\\033[X<\/strong><b>;Y<\/b><strong>m\\]<\/strong><\/p>\n<p>Where <strong>X<\/strong> is the attribute and <strong>Y<\/strong> is the color.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Color<\/strong><\/td>\n<td><strong>Value<\/strong><\/td>\n<\/tr>\n<tr>\n<td>Green<\/td>\n<td>32<\/td>\n<\/tr>\n<tr>\n<td>Red<\/td>\n<td>31<\/td>\n<\/tr>\n<tr>\n<td>Black<\/td>\n<td>30<\/td>\n<\/tr>\n<tr>\n<td>Blue<\/td>\n<td>34<\/td>\n<\/tr>\n<tr>\n<td>Cyan<\/td>\n<td>36<\/td>\n<\/tr>\n<tr>\n<td>Purple<\/td>\n<td>35<\/td>\n<\/tr>\n<tr>\n<td>Yellow<\/td>\n<td>33<\/td>\n<\/tr>\n<tr>\n<td>White<\/td>\n<td>37<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Most common attributes:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Attribute Value<\/strong><\/td>\n<td><strong>Purpose<\/strong><\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>Normal text (default, even if no attribute is set)<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>Bold text (in the Ubuntu Terminal)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Dim text<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Underlined text<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>Blinking text<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>Reversed text and background colors<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>Hidden text<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<p><strong>BUG FIXING<\/strong><\/p>\n<p>A common issue with prompt customization is that keyboard history navigation using the up and down arrow keys can break.<\/p>\n<p>A workaround is to wrap non-printing characters in &#8216;<strong>[]<\/strong>&#8216; within your <strong>PS1<\/strong> variable, like this:<\/p>\n<pre>export PS1=\"\\[\\e[m\\]\\u@\\e[1;31m\\h\\e[m \\W \u21e8 \\[\\e[m\\] \"<\/pre>\n<pre>export PS1=\"\\[\\e[m\\]\\u@<strong>\\[<\/strong>\\e[1;31m\\]\\h<strong>\\[<\/strong>\\e[m\\] \\W \u21e8 \\[\\e[m\\] \"<\/pre>\n<p><strong>Have fun!<\/strong><\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>For privacy when sharing or recording your screen, consider this prompt:<\/p>\n<pre>export PS1=\"\\[$(tput setaf 4)\\]$ \\[$(tput sgr0)\\]\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4233\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2024-05-01-17-51-43.png\" alt=\"\" width=\"620\" height=\"60\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2024-05-01-17-51-43.png 620w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2024-05-01-17-51-43-300x29.png 300w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>On Kali:<\/p>\n<pre>export PS1=\"%F{%(#.blue.green)}\u250c\u2500\u2500${debian_chroot:+()\u2500}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))\u2500}[%B%F{reset}%(6~.%-1~\/\u2026\/%4~.%5~)%b%F{%(#.blue.green)}] \r\n\u2514\u2500%B%(#.%F{red}#.%F{blue}$)%b%F{reset} \"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4235\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/10\/Screenshot-from-2024-05-01-18-05-03.png\" alt=\"\" width=\"295\" height=\"130\" \/><\/p>\n<p>TrueNAS-based style:<\/p>\n<pre>PS1=\"\\[\\033[44m\\]\\u@\\h\\[\\033[0m\\] \\[\\033[1m\\]\\[\\033[36m\\]\\W\\[\\033[37m\\] \\$\\[\\033[0m\\] \"\r\nPS1=\"\\[\\033[41m\\]\\u@\\h\\[\\033[0m\\] \\[\\033[1m\\]\\[\\033[38m\\]\\w\\[\\033[37m\\] \\$\\[\\033[0m\\] \"\r\nPS1=\"\\[\\033[42m\\]\\u@\\h\\[\\033[0m\\] \\[\\033[1m\\]\\[\\033[33m\\]\\W\\[\\033[37m\\] \\$\\[\\033[0m\\] \"\r\nPS1=\"\\[\\033[45m\\]\\u@\\h\\[\\033[0m\\] \\[\\033[1m\\]\\[\\033[94m\\]\\W\\[\\033[37m\\] \\$\\[\\033[0m\\] \"\r\nPS1=\"\\[\\033[40m\\]\\u@\\h\\[\\033[0m\\] \\[\\033[1m\\]\\[\\033[92m\\]\\W\\[\\033[37m\\] \\$\\[\\033[0m\\] \"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There is no technical reason to change the color of the terminal console, but anyone [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=451"}],"version-history":[{"count":20,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":5820,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/451\/revisions\/5820"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}