{"id":220,"date":"2016-01-12T15:32:06","date_gmt":"2016-01-12T20:32:06","guid":{"rendered":"http:\/\/wp-p3d2tsa2xh.pairsite.com\/?p=220"},"modified":"2019-02-14T09:15:31","modified_gmt":"2019-02-14T14:15:31","slug":"paircloud-tutorial-using-the-shell-part-3","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/","title":{"rendered":"Tutorial: Using the Shell, Part 3"},"content":{"rendered":"<h3 class=\"kb\">Introduction<\/h3>\n<p>You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.<\/p>\n<h3 class=\"kb\">Command line Completion<\/h3>\n<p>If you had to type in <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd \/var\/www\/vhosts\/mydomain.com\/httpdocs\/wp-content\/themes\/mylongthemename\/<\/span> you run the risk of making a mistake or taking forever to get it right. Using the <span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> key to auto-complete directory names can save you a lot of time. Here we will show you how to use it just in the <span style=\"font-family: monospace; background-color: #e4e4e4;\">\/<\/span> directory, for the sake of simplicity. Type in <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd \/<\/span> then type in <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd v<\/span> and hit the tab key. Now type in <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd \/h<\/span> and hit the <span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span>.<br \/>\nAs you can see, the\u00a0<span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> key will try to complete the directory name for you. If you have two directories that have the same beginning, it will complete as far as it can, then ask you to give one more letter, after which you can hit\u00a0<span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> again. For example, if you have two directories <span style=\"font-family: monospace; background-color: #e4e4e4;\">documents<\/span> and <span style=\"font-family: monospace; background-color: #e4e4e4;\">documentation<\/span>, you would type <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd d<\/span> tab and it would give you <span style=\"font-family: monospace; background-color: #e4e4e4;\">documentation<\/span> and sound the bell, at which point you could hit a and\u00a0<span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> again and it would give the rest of <span style=\"font-family: monospace; background-color: #e4e4e4;\">documents<\/span>. If it dings halfway through a directory name and you don\u2019t know what your options are hit\u00a0<span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> again and it will list them for you. This double <span style=\"font-family: monospace; background-color: #e4e4e4;\">tabtab<\/span> can be very useful.<\/p>\n<p>This can also be used for commands as well. Try typing in <span style=\"font-family: monospace; background-color: #e4e4e4;\">di<\/span> tab it will ding once, hit the\u00a0<span style=\"font-family: monospace; background-color: #e4e4e4;\">tab<\/span> again and it will list your options.<\/p>\n<h3 class=\"kb\">History<\/h3>\n<p>Did you know that you can go back through previous commands that you have used by using the up arrow?<\/p>\n<h3 class=\"kb\">Searching your history<\/h3>\n<p>If you used the <span style=\"font-family: monospace; background-color: #e4e4e4;\">find<\/span> command mentioned in <a href=\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-2\/\">Part 2 of this series<\/a> and want to use it again today, but don't want to retype it, try using the <span style=\"font-family: monospace; background-color: #e4e4e4;\">CTRL<\/span> + <span style=\"font-family: monospace; background-color: #e4e4e4;\">r<\/span> command. This lets you search backward through your past commands for the one you used previously. In this case, hit <span style=\"font-family: monospace; background-color: #e4e4e4;\">CTRL<\/span> + <span style=\"font-family: monospace; background-color: #e4e4e4;\">r<\/span>\u00a0, then type <span style=\"font-family: monospace; background-color: #e4e4e4;\">find<\/span>\u00a0, then keep hitting <span style=\"font-family: monospace; background-color: #e4e4e4;\">CTRL<\/span> + <span style=\"font-family: monospace; background-color: #e4e4e4;\">r<\/span> until your <span style=\"font-family: monospace; background-color: #e4e4e4;\">find<\/span> command shows up. Then hit <span style=\"font-family: monospace; background-color: #e4e4e4;\">enter<\/span>.<\/p>\n<h3 class=\"kb\">Reuse the last command parameters in new command<\/h3>\n<p>You have just entered <span style=\"font-family: monospace; background-color: #e4e4e4;\"> ls -l \/var\/www\/vhosts\/domain.com\/httpdocs\/wp-content\/themes<\/span> and now realize you want to <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd<\/span> into that directory. Type <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd<\/span> then hit <span style=\"font-family: monospace; background-color: #e4e4e4;\">esc<\/span> followed by <span style=\"font-family: monospace; background-color: #e4e4e4;\">.<\/span><\/p>\n<h3 class=\"kb\">Clearing to the beginning of the line<\/h3>\n<p>If you have just typed in a particularly long path for a command and realized you have the wrong command, go to the end of the command using your left and right cursor keys. Then hit <span style=\"font-family: monospace; background-color: #e4e4e4;\">CTRL<\/span> + <span style=\"font-family: monospace; background-color: #e4e4e4;\">u<\/span>.<\/p>\n<h3 class=\"kb\">Using <span style=\"font-family: monospace; background-color: #e4e4e4;\">shopt<\/span><\/h3>\n<p>The <span style=\"font-family: monospace; background-color: #e4e4e4;\">shopt<\/span> command is short for <strong>shell options<\/strong>. If you run the <span style=\"font-family: monospace; background-color: #e4e4e4;\">shopt<\/span> command on its own, it will list all the options and their current settings.<\/p>\n<h3 class=\"kb\">Setting long path names as a variable<\/h3>\n<p>Run this command <span style=\"font-family: monospace; background-color: #e4e4e4;\">shopt -s cdable_vars<\/span>. Then you can create aliases for long directories.<br \/>\nFor example: <span style=\"font-family: monospace; background-color: #e4e4e4;\">export Dmydomain.com=\"\/var\/www\/vhosts\/mydomain.com\/httpdocs\/\"<\/span>. You can then go straight to your domains main directory by using <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd Dmydomain.com<\/span><\/p>\n<p>Use the leading capital D so you know it is a Directory expansion.<\/p>\n<h3 class=\"kb\">Separating commands using <span style=\"font-family: monospace; background-color: #e4e4e4;\">;<\/span><\/h3>\n<p>You can put two commands on one line by using the <span style=\"font-family: monospace; background-color: #e4e4e4;\">;<\/span>. On its own, this is not of great use, but it does combine with other features of bash to prove quite useful.<\/p>\n<h3 class=\"kb\">Temporarily changing working directory to execute a command<\/h3>\n<p>In bash, you can group commands together using <span style=\"font-family: monospace; background-color: #e4e4e4;\">()<\/span>. A useful trick is to combine a <span style=\"font-family: monospace; background-color: #e4e4e4;\">cd<\/span> operation with another command, but return to your original directory.<br \/>\nFor instance, if you are in <strong>\/root<\/strong> and working there, but want to temporarily go to <strong>\/var\/www\/domain.com<\/strong> and execute a command, you could do:<\/p>\n<pre>cd \/var\/www\/domain.com\r\ncommand\r\ncd -<\/pre>\n<p>Or you could do:<\/p>\n<pre>(cd \/var\/www\/domain.com;command)<\/pre>\n<h3 class=\"kb\">Conclusion<\/h3>\n<p>There are lots of tricks and secrets in the bash shell and any downtime you have spent searching them out can be repaid in time saved later. We hope the few we have explained here have given you some speedier ways of doing things.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient. Command line Completion If you had to type in cd \/var\/www\/vhosts\/mydomain.com\/httpdocs\/wp-content\/themes\/mylongthemename\/ you run the risk of making a mistake or taking forever to get it right. Using the&#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 3 - Knowledge Base - Pair Networks<\/title>\n<meta name=\"description\" content=\"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.\" \/>\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-3\/\" \/>\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 3 - Knowledge Base - Pair Networks\" \/>\n<meta property=\"og:description\" content=\"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/\" \/>\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:31+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-3\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/\",\"name\":\"Tutorial: Using the Shell, Part 3 - Knowledge Base - Pair Networks\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-01-12T20:32:06+00:00\",\"dateModified\":\"2019-02-14T14:15:31+00:00\",\"description\":\"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/#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 3\"}]},{\"@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 3 - Knowledge Base - Pair Networks","description":"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.","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-3\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial: Using the Shell, Part 3 - Knowledge Base - Pair Networks","og_description":"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.","og_url":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2019-02-14T14:15:31+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-3\/","url":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/","name":"Tutorial: Using the Shell, Part 3 - Knowledge Base - Pair Networks","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-01-12T20:32:06+00:00","dateModified":"2019-02-14T14:15:31+00:00","description":"You can be very productive using the shell, however there are some fantastic tricks to make you faster and more efficient.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-tutorial-using-the-shell-part-3\/#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 3"}]},{"@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\/220"}],"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=220"}],"version-history":[{"count":9,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/220\/revisions"}],"predecessor-version":[{"id":6631,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/220\/revisions\/6631"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=220"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}