{"id":222,"date":"2016-01-12T15:31:58","date_gmt":"2016-01-12T20:31:58","guid":{"rendered":"http:\/\/wp-p3d2tsa2xh.pairsite.com\/?p=222"},"modified":"2019-02-14T09:15:40","modified_gmt":"2019-02-14T14:15:40","slug":"paircloud-tutorial-using-the-shell-part-4","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/","title":{"rendered":"Tutorial: Using the Shell, Part 4"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Your shell can be personalized quite a lot. Using settings in your <strong>.bashrc<\/strong> file you can change the prompt, set up aliases and much more.<\/p>\n<h3 class=\"kb\">Activating changes<\/h3>\n<p>Once you have edited your <strong>.bashrc<\/strong> file you will want to activate the changes without logging out and back in again. Use <span style=\"font-family: monospace; background-color: #e4e4e4;\">source ~\/.bashrc<\/span> to do this.<\/p>\n<h3 class=\"kb\">The prompt<\/h3>\n<p>The standard prompt is a pretty boring and basic item. You can make it more useful by configuring it to display information you need and change the colors to make it stand out.<\/p>\n<p>If you do most of your work on the bash prompt as a normal user but occasionally <span style=\"font-family: monospace; background-color: #e4e4e4;\">su<\/span>to root, it is nice to have a clear indication that you are root. One way to do this is to set the color of the prompt to be green for a normal user and red for root. To do this you need to edit the two <strong>.bashrc<\/strong> files: <strong>~\/.bashrc<\/strong> and <strong>\/root\/.bashrc<\/strong><br \/>\nIn your <strong>~\/.bashrc<\/strong> file add this line:<\/p>\n<pre>PS1='\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] '<\/pre>\n<p>In your \/root\/.bashrc add this line<\/p>\n<pre>PS1='\\[\\e[1;31m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] '<\/pre>\n<p>The first part <span style=\"font-family: monospace; background-color: #e4e4e4;\">\\[\\e[1;32m\\]<\/span> and <span style=\"font-family: monospace; background-color: #e4e4e4;\">\\[\\e[1;31m\\]<\/span> sets the color. The last part <span style=\"font-family: monospace; background-color: #e4e4e4;\">\\[\\e[0m\\]<\/span> returns the color to white. The bits in between <span style=\"font-family: monospace; background-color: #e4e4e4;\">[\\u@\\h \\W]\\$<\/span> are what give you the information <span style=\"font-family: monospace; background-color: #e4e4e4;\">username @ hostname<\/span>.<\/p>\n<p>In this ANSI color code, <span style=\"font-family: monospace; background-color: #e4e4e4;\">\\[\\e[1;32m\\]<\/span>, the ANSI color codes are the bits inside the inner brackets: <span style=\"font-family: monospace; background-color: #e4e4e4;\">1;32m<\/span>. If there is a semicolon, <span style=\"font-family: monospace; background-color: #e4e4e4;\">;<\/span>, then the first part is the modifier and the second part is the color. In this case the <strong>1<\/strong> means <strong>bold<\/strong>. The colors can be any of these:<\/p>\n<pre>30 = Black\r\n31 = Red\r\n32 = Green\r\n33 = Yellow\r\n34 = Blue\r\n35 = Magenta\r\n36 = Cyan\r\n37 = White<\/pre>\n<p>If you just wanted normal red you would use <span style=\"font-family: monospace; background-color: #e4e4e4;\">31m<\/span> instead of <span style=\"font-family: monospace; background-color: #e4e4e4;\">1;31m<\/span>. To reset the color back to default you use <span style=\"font-family: monospace; background-color: #e4e4e4;\">0m<\/span>.<\/p>\n<p>The individual parts are as follows<br \/>\n\\u \u2013 Username.<br \/>\n\\h \u2013 Hostname.<br \/>\n\\w \u2013 Current absolute path. Use \\W for current relative path.<br \/>\n\\$ \u2013 The prompt character This will be # for user root, $ for regular users).<\/p>\n<p>There are lots of other escape codes you can use in your prompt. To find out more please see <span style=\"font-family: monospace; background-color: #e4e4e4;\">man bash<\/span> and search for PROMPTING.<\/p>\n<h3 class=\"kb\">If you are new to using root<\/h3>\n<p>Enter this in your <span style=\"font-family: monospace; background-color: #e4e4e4;\">\/root\/.bashrc<\/span>:<\/p>\n<pre>shopt -o noclobber<\/pre>\n<p>This noclobber prevents you from overwriting a file with a redirect by accident. If you then want to force the issue use <span style=\"font-family: monospace; background-color: #e4e4e4;\">&gt;|filename.txt<\/span>.<\/p>\n<h3 class=\"kb\">Put lots of useful information on the title bar<\/h3>\n<p>In <strong>.bashrc<\/strong> this gives the \"username @ full hostname\" and the full working directory.<\/p>\n<pre>case \"$TERM\" in\r\nxterm*|rxvt*)\r\n    PS1=\"\\[\\e]0;\\u@\\H: \\w\\a\\]$PS1\"\r\n    ;;\r\n*)\r\n    ;;\r\nesac<\/pre>\n<h3 class=\"kb\">Tidying up the history<\/h3>\n<p>You can ensure that you get no duplicates in you history file. For example, you might type <span style=\"font-family: monospace; background-color: #e4e4e4;\">ls -la<\/span> a lot and don\u2019t want your history file full of these. You can add this line to your <strong>.bashrc<\/strong>:<\/p>\n<pre>export HISTCONTROL=ignoredups<\/pre>\n<h3 class=\"kb\">Getting IP addresses<\/h3>\n<p>Quite often you will need either the server's IP or the IP you are connecting from. These functions make that information immediately available.<\/p>\n<pre>serverip() {\r\n        \/sbin\/ifconfig eth0 | grep 'inet ' | awk {'print $2'} | sed -e s\/addr:\/\/\r\n        }\r\n\r\nmyip () {\r\n        who | awk {'print $5'} | tr -d '(),'\r\n        }<\/pre>\n<p>Now when you type either <span style=\"font-family: monospace; background-color: #e4e4e4;\">serverip<\/span> or <span style=\"font-family: monospace; background-color: #e4e4e4;\">myip<\/span> at the prompt you will get the relevant IP address immediately.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Your shell can be personalized quite a lot. Using settings in your .bashrc file you can change the prompt, set up aliases and much more. Activating changes Once you have edited your .bashrc file you will want to activate the changes without logging out and back in again. Use&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[203],"ht-kb-tag":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks<\/title>\n<meta name=\"description\" content=\"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks\" \/>\n<meta property=\"og:description\" content=\"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - Pair Networks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pairnetworks\/\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-14T14:15:40+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@pairNetworks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/\",\"name\":\"Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-01-12T20:31:58+00:00\",\"dateModified\":\"2019-02-14T14:15:40+00:00\",\"description\":\"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pair.com\/support\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial: Using the Shell, Part 4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"name\":\"Knowledge Base - Pair Networks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\",\"name\":\"Pair Networks\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"contentUrl\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"width\":360,\"height\":360,\"caption\":\"Pair Networks\"},\"image\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pairnetworks\/\",\"https:\/\/twitter.com\/pairNetworks\",\"https:\/\/www.instagram.com\/pairnetworks\/\",\"https:\/\/www.linkedin.com\/company\/2269676\/\",\"https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/\",\"https:\/\/www.youtube.com\/user\/pairnetworks\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks","description":"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks","og_description":"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.","og_url":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2019-02-14T14:15:40+00:00","twitter_card":"summary_large_image","twitter_site":"@pairNetworks","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/","url":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/","name":"Tutorial: Using the Shell, Part 4 - Knowledge Base - Pair Networks","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-01-12T20:31:58+00:00","dateModified":"2019-02-14T14:15:40+00:00","description":"Your shell can be personalized quite a lot. Using settings in your .bashrc file, you can change the prompt, set up aliases and much more.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pair.com\/support\/kb\/"},{"@type":"ListItem","position":2,"name":"Tutorial: Using the Shell, Part 4"}]},{"@type":"WebSite","@id":"https:\/\/www.pair.com\/support\/kb\/#website","url":"https:\/\/www.pair.com\/support\/kb\/","name":"Knowledge Base - Pair Networks","description":"","publisher":{"@id":"https:\/\/www.pair.com\/support\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pair.com\/support\/kb\/#organization","name":"Pair Networks","url":"https:\/\/www.pair.com\/support\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","contentUrl":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","width":360,"height":360,"caption":"Pair Networks"},"image":{"@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pairnetworks\/","https:\/\/twitter.com\/pairNetworks","https:\/\/www.instagram.com\/pairnetworks\/","https:\/\/www.linkedin.com\/company\/2269676\/","https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/","https:\/\/www.youtube.com\/user\/pairnetworks"]}]}},"_links":{"self":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/222"}],"collection":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":5,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/222\/revisions"}],"predecessor-version":[{"id":6632,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/222\/revisions\/6632"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=222"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}