{"id":28,"date":"2019-05-01T04:58:21","date_gmt":"2019-05-01T09:58:21","guid":{"rendered":"https:\/\/codeblock.supadupa.rocks\/?p=28"},"modified":"2020-09-08T13:29:07","modified_gmt":"2020-09-08T18:29:07","slug":"cut","status":"publish","type":"post","link":"https:\/\/client35.dev\/code\/cut\/","title":{"rendered":"Cut"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute<\/span><\/span>\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/client35.dev\/code\/wp-content\/uploads\/sites\/2\/2019\/05\/kitchen-knife-1024x679.jpg\" alt=\"\" class=\"wp-image-29\" width=\"627\" height=\"415\"\/><\/figure><\/div>\n\n\n\n<p class=\"has-drop-cap wp-block-paragraph\">There&#8217;s no way to <strong>cut<\/strong> <strong>it<\/strong> when it comes to telling you how to use this great tool! <br><br>Whenever I&#8217;ve used it, I commonly use it in lieu of a user&#8217;s home directory: <br><code>$(pwd | cut -d\\\/ -f5)<\/code>. This helps me save time from copy and pasting the install name, however it doesn&#8217;t always work. <br>For example, if we&#8217;re not in <code>\/path\/to\/live\/SITE<\/code> or <code>\/path\/to\/log\/SITE<\/code> then cut can&#8217;t grab the appropriate path. Let me break it down by first running <code>pwd.<\/code> <br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">spencer@local:\/nas\/content\/live\/dubtraxx\/wp-content\/themes\/minimum-pro$ pwd\n\/nas\/content\/live\/dubtraxx\/wp-content\/themes\/minimum-pro<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We see that it&#8217;s <code>printing<\/code> the  <code>working directory<\/code>, all the way up to the directory we&#8217;re in. PWD is just printing the folder I&#8217;m currently in, including the server&#8217;s absolute path. Whenever you include the <code>-d<\/code> you&#8217;re telling <code>pwd<\/code> that you want to use <code>\/<\/code> as your delimiter (separator). <br>However, since <code>\/<\/code>is a special character in Linux&#8217;s bash shell, we need to escape it by adding a backslash <code>\\<\/code>. <br><br>On this note, it&#8217;s also perfectly acceptable to use <code>-d'\/'<\/code> instead of a <code>\\<\/code> to signal the delimiter of choice to <code>cut<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s take a look at what happens if we run the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;application\/x-sh&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">spencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f2\npath\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f3\nto\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f4\nlive\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f5\ndubtraxx\n<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">And for some testing&#8230;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;application\/x-sh&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">spencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d'\/' -f4-\nlive\/dubtraxx\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f2-\npath\/to\/live\/dubtraxx\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f1\n\nspencer@local~ :\/path\/to\/live\/dubtraxx $ pwd | cut -d\\\/ -f1-\n\/path\/to\/live\/dubtraxx<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">There are many more uses for cut, but we&#8217;ll go over those in another tutorial. <br>Ciao! <\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute<\/span><\/span>There&#8217;s no way to cut it when it comes to telling you how to use this great tool! Whenever I&#8217;ve used it, I commonly use it in lieu of a user&#8217;s home directory: $(pwd | cut -d\\\/ -f5). This helps me save time from copy and pasting the install name, however it doesn&#8217;t always work. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-command-line-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/client35.dev\/code\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}