<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dave Kerr on Medium]]></title>
        <description><![CDATA[Stories by Dave Kerr on Medium]]></description>
        <link>https://medium.com/@dwmkerr?source=rss-5a88ed9a4248------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*m7DLrnr9FEjWwN1Iq3Cmvw.jpeg</url>
            <title>Stories by Dave Kerr on Medium</title>
            <link>https://medium.com/@dwmkerr?source=rss-5a88ed9a4248------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 19:25:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dwmkerr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Effective Shell Part 1: Navigating the Command Line]]></title>
            <link>https://medium.com/@dwmkerr/effective-shell-part-1-navigating-the-command-line-59cade9085db?source=rss-5a88ed9a4248------2</link>
            <guid isPermaLink="false">https://medium.com/p/59cade9085db</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dave Kerr]]></dc:creator>
            <pubDate>Mon, 12 Jun 2017 04:50:40 GMT</pubDate>
            <atom:updated>2017-07-15T13:17:24.062Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the <a href="https://github.com/dwmkerr/effective-shell">first part of a series</a> I writing which contains practical tips for using the shell more effectively.</p><p>I can’t think of a better place to start than <em>navigating the command line</em>. As you start to do more and more in the shell, text in the command line can quickly become hard to handle. In this article I’ll show some simple tricks for working with the command line more effectively.</p><p>Here’s a quick reference diagram, the rest of the article goes into the details!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UrEZ9VHCtZozzjFO.png" /></figure><p>This article, examples and diagrams are available at <a href="https://github.com/dwmkerr/effective-shell">github.com/dwmkerr/effective-shell</a>.</p><p>Let’s assume we have a very simple command we are writing, which is going to write a quote to a text file:</p><pre>echo &quot;The trouble with writing fiction is that it has to make sense, whereas real life doesn&#39;t. -- Iain M. Banks&quot; &gt;&gt; quote.txt</pre><p>Navigating around long lines of text is a slow process if you are only relying on the arrow keys, so take the time to learn the following shortcuts:</p><p>Go to beginning / end - Ctrl + a, Ctrl + e</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*zSbUikJ8pFnUbstz.gif" /></figure><p>Go backwards / forwards one word - Alt + b / Alt + f</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*Y_rTmmR8IYh3GiZo.gif" /></figure><p>Delete a word / undo - Ctrl + w / Ctrl + -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*OjnDfpQ6GLqx0x1A.gif" /></figure><p>Delete next word - Alt + d</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*_dxghkZX3JX4IQU1.gif" /></figure><p>Delete all the way to the beginning<a href="http://www.dwmkerr.com/effective-shell-part-1-navigating-the-command-line/#fn:1">1</a> - Ctrl + u</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*fWk55wtrybagAiK6.gif" /></figure><p>Delete all the way to the end - Ctrl + k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*GL1mozjDkpP4Q7i-.gif" /></figure><h3>Searching</h3><p>Once you have the basic navigation commands down, the next essential is searching. Let’s assume we’ve run the following three commands:</p><pre>$ command1 param1 param2 param3 $ command2 param4 param5 param6 $ command3 param7 param8 param9</pre><p>You can search backwards or forwards with Ctrl + r and Ctrl + s. This will search in the current command and then iteratively through previous commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*fWDviGycCP4xSvMM.gif" /></figure><p>This is useful for searching in the current command, but can be also used to quickly search backwards and forwards through the command history:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*c9TzMjvj2Cm2iY1R.gif" /></figure><p>As you type, your command history is searched, the most recent commands coming first. Use the arrow keys to edit the command, press enter to execute it, or Ctrl + g to cancel the search.</p><p>Here are the same commands applied to the original example:</p><p>Search backwards / forwards - Ctrl + r / Ctrl + s</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*9RiRp81OrM-Q6r1c.gif" /></figure><p>Run the command -Enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*tJskCheNjHf_ucgY.gif" /></figure><p>Edit the command - Right Arrow / Right Arrow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*iaBjRVfnGLpb-To0.gif" /></figure><p>Stop searching - Ctrl + g</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*TWKuO7HSDd7q6ugx.gif" /></figure><h3>Editing In-Place</h3><p>These tips and tricks are helpful, but if you are working with a really long or complex command, you might find it useful just to jump into your favourite editor.</p><p>Use Ctrl + x , Ctrl + e to edit-in place:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*zKQU3YnD3EyTk1TL.gif" /></figure><p>In a later article I’ll talk a little more about how to configure the default editor.</p><p>Probably the shortcut I use the most is Ctrl + l, which clears the screen without trashing your current command. Here&#39;s how it looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*dVaMXE9zfkOaVnai.gif" /></figure><h3>Pro Tip: Transposing!</h3><p>If you’ve mastered all of the commands here and feel like adding something else to your repertoire, try this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*h4DFy_9KwrZupwFZ.gif" /></figure><p>The Alt + t shortcut will transpose the last two words. Use Ctrl + t to transpose the last two letters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*TvJA94OC4DZajZ7V.gif" /></figure><p>These were new to me when I was researching for this article. I can’t see myself ever being able to remember the commands more quickly than just deleting the last two words or characters and re-typing them, but there you go!</p><h3>Closing Thoughts</h3><p>If you are ever looking to go deeper, then search the web for <em>GNU Readline</em>, which is the library used under the hood to handle the command line in many shells. You can actually configure lower level details of how all shells which use readline work, with the <a href="https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File.html">.inputrc</a> configuration file.</p><p>The great thing about learning these shortcuts is that they will work in any prompt which uses GNU Readline. This means everything you’ve learnt applies to:</p><ol><li>Bash</li><li>zsh</li><li>The Python REPL</li><li>The Node.js REPL</li></ol><p>And probably a whole bunch more<a href="http://www.dwmkerr.com/effective-shell-part-1-navigating-the-command-line/#fn:2">2</a>.</p><p>All of these shortcuts should be familiar to Emacs users. There is in fact a ‘Vi Mode’ option for readline, which allows you to use vi commands to work with text. You can enter this mode with set -o vi, I&#39;ll likely come back to this in detail in a later article.</p><p>There’s a great cheat sheet on emacs readline commands at <a href="http://readline.kablamo.org/emacs.html">readline.kablamo.org/emacs</a>, which is a very useful reference if you want to dig deeper. For this article I’ve tried to focus on what I think are the most useful commands (and transpose just so you can show off!).</p><p>Hope that was useful! GIFs were made with <a href="http://www.cockos.com/licecap/">LICEcap</a>.</p><p><em>Originally published at </em><a href="http://www.dwmkerr.com/effective-shell-part-1-navigating-the-command-line/"><em>www.dwmkerr.com</em></a><em> on June 12, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59cade9085db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>