{"id":1444,"date":"2016-09-12T14:27:04","date_gmt":"2016-09-12T19:27:04","guid":{"rendered":"http:\/\/www.serverpronto.com\/spu\/?p=1444"},"modified":"2018-06-27T15:10:02","modified_gmt":"2018-06-27T20:10:02","slug":"some-simple-and-useful-command-line-tips","status":"publish","type":"post","link":"https:\/\/www.serverpronto.com\/spu\/2016\/09\/some-simple-and-useful-command-line-tips\/","title":{"rendered":"Useful Command Line Tips"},"content":{"rendered":"<p style=\"text-align: left;\">A standout among the most helpful, yet under-utilized, tools a web developer has is the command-line. The terminal frequently frightens people away; so here&#8217;s the place we demonstrate some of the most helpful day-to-day commands.<\/p>\n<p><!--more--><\/p>\n<h2>Show Current Directory Path (pwd)<\/h2>\n<p>Often when dashing around projects (particularly when multitasking), it&#8217;s helpful to rapidly double-check which directory you&#8217;re at present in. You can do this with the pwd command. This will provide the full path to the present directory.<\/p>\n<h2>Line Numbering (nl)<\/h2>\n<p>This is a frequently used command, yet doesn&#8217;t look to be very well known. Want to rapidly output the contents of a file with line numbers, but would prefer need not to open up your text editor? Well, fortunately, nl has got you covered. Basically, run nl &lt;filename&gt; and you will be quickly given something like this.<br \/>\n1 var elixir = require(&#8216;laravel-elixir&#8217;);<br \/>\n2 \/*<br \/>\n3 |&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n4 | Elixir Asset Management<br \/>\n5 |&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n6 |<br \/>\n7 | Elixir provides a clean, fluent API for defining some basic Gulp tasks<br \/>\n8 | for your Laravel application. By default, we are compiling the Sass<br \/>\n9 | file for our application, as well as publishing vendor resources.<br \/>\n10 |<br \/>\n11 *\/<br \/>\n12 elixir(function(mix) {<br \/>\n13 mix.sass(&#8216;app.scss&#8217;);<br \/>\n14 });<\/p>\n<h2>Command Aliasing (alias)<\/h2>\n<p>On the off chance that you end up writing the same long-winded commands, again and again, it might be a clue that you ought to set up an alias. Take the following illustration:<\/p>\n<p>$ vendor\/bin\/phpunit \u00e2\u20ac\u201ccolors<br \/>\nIn order to run the unit tests, make the use of this command fairly regularly and you don\u00e2\u20ac\u2122t have to type it again and again. Yes, you can simply make the use of arrow keys to cycle via commands but if have run a number of commands recently, this will take pretty much as long. Why not simply set up an alias?<br \/>\n$ alias t=&#8221;vendor\/bin\/phpunit &#8211;colors&#8221;<br \/>\nAt that point all you have to do is simply run t and the full command will be executed.<\/p>\n<h2>Searching Content of Files (grep)<\/h2>\n<p>Need to search a specific bit of code, knowing it could be anywhere in the huge abyss of documents that is your codebase? No need to worry as grep is here for you. Let&#8217;s assume you need to find the file in which a str_slug() capacity is declared. You can simply do that with the below-given command:<br \/>\n$ grep &#8211;ignore-case &#8211;recursive &#8216;function str_slug&#8217; *<br \/>\nIt\u00e2\u20ac\u2122s fairly self-explanatory, but let\u00e2\u20ac\u2122s have a quick run through the anatomy of the above.<br \/>\n\u00e2\u20ac\u00a2 grep \u00e2\u20ac\u201c this is the command name \u00e2\u20ac\u201c obviously.<\/p>\n<p>\u00e2\u20ac\u00a2 &#8211;ignore-case \u00e2\u20ac\u201c tells the command to make the search case-insensitive.<br \/>\n\u00e2\u20ac\u00a2 &#8211;recursive \u00e2\u20ac\u201c tells the command to search recursively, so it will automatically enter any directories and search the files within them.<\/p>\n<p>\u00e2\u20ac\u00a2 &#8216;function str_slug&#8217; \u00e2\u20ac\u201c this is the search pattern. This is what the command will look for in the files it searches.<br \/>\n\u00e2\u20ac\u00a2 * \u00e2\u20ac\u201c search in all files and directories (within the present directory). This can also be a directory path or file name.<br \/>\nAnd just FYI, we can consolidate the option names and shorten the command to this:<\/p>\n<p>$ grep -ir &#8216;function str_slug&#8217; *<\/p>\n<h2>Repeat Previous Command (!!)<\/h2>\n<p>There may be times when you try to execute a command but it only comes up with an \u00e2\u20ac\u0153 access denied\u00e2\u20ac\u009d error. Then make the use of up arrow to enter the previous command into the window and hold the left arrow key until you are at the starting to prefix the entire thing with sudo. And next time if you go through this issue, simply try running sudo, trailed by two exclamation marks like so: sudo!!. This works with any command.<\/p>\n<h2>Output to File (&gt;)<\/h2>\n<p>We all know how to get a string to the terminal (echo \u00e2\u20ac\u02dcfoo\u00e2\u20ac\u2122), but what if we needed to place that into a file? Well, we could make the file by running vi example.txt, then entering the content and saving, but what if this could be done with one command? Try this:<\/p>\n<p>$ echo &#8216;foo&#8217; &gt; example.txt<br \/>\nYou simply run Is, you should see example.txt recorded. Now, if you open up the file in your text editor (or then again, utilize cat example.txt to speedily get the contents of the file), you should see the content \u00e2\u20ac\u0153foo\u00e2\u20ac\u009d.<\/p>\n<p><a href=\"https:\/\/www.serverpronto.com\">ServerPronto<\/a> offers the best affordable and secure hosting service in all dedicated server packages.<\/p>\n<p><button id=\"post_tag-check-num-2\" class=\"ntdelbutton\" type=\"button\"><span class=\"screen-reader-text\"><a href=\"https:\/\/www.serverpronto.com\">ServerPronto<\/a> offers the best affordable and secure hosting service in all dedicated server packages.<a href=\"https:\/\/www.serverpronto.com\">ServerPronto<\/a> offers the best affordable and secure hosting service in all dedicated server packa<\/span><\/button><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A standout among the most helpful, yet under-utilized, tools a web developer has is the command-line. The terminal frequently frightens people away; so here&#8217;s the place we demonstrate some of the most helpful day-to-day commands.<\/p>\n","protected":false},"author":9,"featured_media":751,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"footnotes":""},"categories":[201,134],"tags":[123,210,178,17,112,22,18,207],"class_list":["post-1444","post","type-post","status-publish","format-image","has-post-thumbnail","category-web-servers","category-website-hosting-2","tag-cloud","tag-command","tag-command-line","tag-dedicated-server","tag-hosting","tag-server","tag-web-hosting","tag-website-optimization","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/comments?post=1444"}],"version-history":[{"count":8,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/1444\/revisions"}],"predecessor-version":[{"id":2282,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/1444\/revisions\/2282"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/media\/751"}],"wp:attachment":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/media?parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/categories?post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/tags?post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}