<?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 Lam Bui on Medium]]></title>
        <description><![CDATA[Stories by Lam Bui on Medium]]></description>
        <link>https://medium.com/@lamdbui?source=rss-7309c782a5cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rQYBhwf6_Ws-YQnH.</url>
            <title>Stories by Lam Bui on Medium</title>
            <link>https://medium.com/@lamdbui?source=rss-7309c782a5cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:39:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lamdbui/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[Faster command-line workflow with tmux]]></title>
            <link>https://medium.com/@lamdbui/faster-command-line-workflow-with-tmux-a6539c8eae2c?source=rss-7309c782a5cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6539c8eae2c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[tmux]]></category>
            <category><![CDATA[workflow]]></category>
            <dc:creator><![CDATA[Lam Bui]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 05:56:24 GMT</pubDate>
            <atom:updated>2017-10-11T05:56:24.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9svlZjdOviDuXNnKm40wA.png" /><figcaption>Time to go through hyperspace (with tmux)!</figcaption></figure><p>As we all grow as developers, learning how to be efficient and improving our workflow is one best things we can do to become better engineers. The faster you can accomplish a task and reduce potential points of error, the more you can get done. Today, I’m going to talk about one of my favorite efficiency tools — tmux</p><blockquote>tmux is a command-line terminal multiplexer with session management</blockquote><p>In practice, you may have run into situations where you need to view multiple terminal consoles at the same time. For example, you may have a few servers running (e.g. web, database, debugger) and you might want to monitor all the output coming from these servers in real-time to validate behavior or run commands. Or maybe you want to run vim in a terminal window to sling some code and a plain command-line in another window for testing.</p><p>Before tmux, you might have just opened a few different tabs in the terminal and switched between them to see the output. Or maybe you resized each terminal window to fit both on the screen at a time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tT5nQ25WJqWdx7Kh7Vaf4A.png" /><figcaption>three(3) separate windows — sadness :(</figcaption></figure><p>These methods work, but are a bit clunky and can be annoying to switch between. You would also have to remember which terminal tab corresponds to what server.</p><p>Thankfully, there’s an easier way — tmux</p><h3>So what is tmux and why do I care?</h3><p>tmux is a command-line terminal multiplexer with session management.</p><p>Here is the same setup as above, but using tmux instead:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FMUYCPmUWnaJUkoZ4IYHpQ.png" /><figcaption>tmux session with windows for vim, man, and command-line</figcaption></figure><p>At its most basic level, tmux allows you to split your single terminal window up into multiple terminal instances(panes). There is also another awesome feature that gives you the ability to save(tmux detach) and retrieve(tmux attach) command-line history from one-or-many terminal sessions on reconnect, which is incredibly powerful — more on this later.</p><p>In a nutshell, here are some of the most popular tmux features:</p><ul><li>Window/Pane management</li><li>Session management with persistence</li><li>Sharable sessions with other users</li><li>Scriptable configurations</li><li>Plugins</li></ul><p>I am a big believer in “learn-by-example,” so let’s explore tmux with some examples.</p><h3>How does it work?</h3><blockquote><strong>Client → Server → Session → Window → Panes</strong></blockquote><p>Again, tmux is a window service that provides session management.</p><p>Here’s a brief walk-through of what is actually happening:</p><p>A client(you) connects to a server(local machine or remote). A tmux service is running in the background on that server and will do the magic of handling session/window management. The user then creates a new tmux session to do some work. Each tmux session contains a Window object (but there can be many) and within each Window, there are one (or many) panes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34-RzOhZF07TCil3O4XPEA.png" /><figcaption>Window — red box, Pane — blue box</figcaption></figure><h3>How do I install it?</h3><p><strong>Linux</strong>: use your distribution’s package manager</p><ul><li>e.g. on Ubuntu-based systems you can do:</li></ul><pre>sudo apt-get install tmux</pre><p><strong>Mac</strong>: use brew package manager</p><ul><li>Install brew , if not installed already — <a href="https://brew.sh/">https://brew.sh/</a></li><li>Then from the command-line:</li></ul><pre>brew install tmux</pre><p><strong>Windows</strong>: Windows 10 → bash Windows 8 (or older)→ Cygwin</p><ul><li>Windows 10: Windows 10 now comes with bash, so many of your favorite Linux utilities are available<br>tmux setup instructions here: <a href="https://blogs.msdn.microsoft.com/commandline/2016/06/08/tmux-support-arrives-for-bash-on-ubuntu-on-windows/">https://blogs.msdn.microsoft.com/commandline/2016/06/08/tmux-support-arrives-for-bash-on-ubuntu-on-windows/</a></li><li>Windows 8 (or older): use Cygwin<br><a href="https://www.cygwin.com/">https://www.cygwin.com/</a></li></ul><p><strong>Hardcore status</strong>: compile tmux yourself :)</p><ul><li><a href="https://github.com/tmux/tmux">https://github.com/tmux/tmux</a></li></ul><p><strong>Verify Your Install</strong></p><p>You can verify that you have installed tmux correctly with:</p><pre>man tmux</pre><p>The terminal will show something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-CtNM6hhVdYwKmUO_kPMTw.png" /><figcaption>man entry for tmux</figcaption></figure><p><em>PRO-TIP: Notice</em><em>man tmux shows </em><em>tmux usage instructions, so make sure to refer back to this as you learn. (Press </em><em>q to exit the </em><em>man page by the way)</em></p><p>After installing on your platform of choice, you’re good to go.</p><h3>Starting a New Session</h3><p>I mentioned before that tmux is also a session manager, so all output that shows up in all terminals(windows/panes) are captured in a session.</p><p>To understand what that means, let’s start by using tmux to create our first session by running the following command:</p><pre>tmux new-session -s &lt;your_session_name&gt; </pre><p><em>Note: You can give the </em>&lt;your_session_name&gt;<em> any name you wish. It’s just used to make it easier to identify which session you want to attach to. By default, the session naming behavior is incrementing ordinal numbers, if none is specified.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a_KIyI8Lz7J_oCnGRBzJAw.png" /><figcaption>newly created session named ‘test’ — notice the colored bar at the bottom</figcaption></figure><p>Great, now you’re in a tmux session. To see available sessions use the following command:</p><pre>tmux list-sessions </pre><p>Now that we have a session running, let’s get to exploring some features. I’m going to cover the two most useful ones below through some common use cases.</p><h3>Controlling a Session</h3><p>With tmux there are a few commands that are useful to know from the start to be able to use tmux effectively. In tmux, actions are accomplished via command-mode(also called prefixing). So, anytime you want to do something tmux related(e.g. splitting panes), you must first put tmux in command-mode to do so and then execute your command(action).</p><p><strong>Using command mode:</strong><br>Enter command-mode: ctrl-b <br>Enter text command-mode: ctrl-b :<br>Exit command-mode: esc <br>List command-mode shortcuts: ctrl-b ?</p><p><strong>So, the process is as follows:</strong></p><ol><li>Enter command mode</li><li>Issue your tmux command</li><li>Exit command mode</li><li>Do your work</li><li>Repeat as needed</li></ol><h3>Use case: Split Panes</h3><p>Say you have a need to view multiple terminal windows at a time. I mentioned before the example of running vim then having a terminal to type your commands in. Maybe you also want to monitor your server at the same time as well. Let’s take a look at how we can use panes to help us do that:</p><ol><li>Start a tmux session:<br>tmux new-session -s &lt;your_session_name&gt;</li><li>To split vertically: <br>ctrl-b %</li><li>To split horizontally: <br>ctrl-b &quot;</li><li>To navigate and select a pane: <br>ctrl-b &lt;arrow keys&gt;</li><li>To toggle full-screen zoom in/out on the current pane:<br>ctrl-b z</li><li>To close the current pane:<br>ctrl-b x then confirm with y or n</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*dl-gCNFupAP1LLr_rgIlHQ.gif" /><figcaption>Split panes example</figcaption></figure><h3>Use case: Session Management</h3><p>I mentioned before that session management is one of the most powerful features of tmux. Sessions allow you to create persistent workspaces that you can connect to and disconnect from at will.</p><p>Here is a hypothetical scenario:</p><p>Let’s say you are at the office and connected to a remote server via SSH. You might be running a test that is printing logs out to the command-line, but it takes a long time(hours). It’s 6pm and you need to get home to feed the dog, but you don’t want to lose your session data when you reconnect again.</p><p>Or maybe you accidentally closed your terminal window — yikes!</p><p>tmux to the rescue! tmux gives you session management for free. Every tmux session is automatically logged and history is retained. You just need to reattach to the session and you have all that work back in addition to the output that happened when you were on your way home or after you accidentally closed your terminal window. Pretty rad, huh?</p><p><strong>Here are the steps:</strong></p><ol><li>Start with a named session:<br>tmux new-session -s &lt;your_session_name&gt;</li><li>Do your work in your tmux session</li><li>Detach from your session when you are done:<br>tmux detach</li><li>[Optional] View available attachable sessions:<br>tmux list-sessions or tmux ls</li><li>Reattach to your tmux session when you are ready to continue working:<br>tmux attach -t &lt;your_session_name&gt;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*7xSaIzqioYyeMA0ctuJGHA.gif" /><figcaption>Session management example</figcaption></figure><h3>Additional Details/Handy Shortcuts</h3><p>tmux is an extremely powerful and useful tool that can supercharge your command-line workflow. I encourage you to give tmux a shot and challenge you to discover a configuration and workflow that fits your personal style.</p><p>The only way to get better is to practice by using tmux in your daily workflow. Below are additional tips and reference material to help you along your tmux and workflow efficiency journey.</p><h4>Common Shortcuts</h4><p>Enter text command-mode: ctrl-b :<br>Enter command-mode: ctrl-b <br>Exit command-mode: esc <br>List command-mode shortcuts: ctrl-b ?<br>Toggle full screen current pane (zoom): ctrl-b z<br>Enable scroll mode: ctrl-b [</p><blockquote>PRO-TIP: when in doubt, the command: ‘man tmux’ is your friend</blockquote><h4>Other Tool Options</h4><p>Though I really like tmux there are a few other tools out there that accomplish similar goals as well.</p><p><strong>GNU Screen</strong> — available on most platforms (open-source software)<br><a href="https://www.gnu.org/software/screen/">https://www.gnu.org/software/screen/</a><br><em>Window manager from GNU</em></p><p><strong>iTerm2</strong> — OS X only<br><a href="https://www.iterm2.com/">https://www.iterm2.com/</a><br><em>Replacement for the default Terminal application</em></p><p><em>Note: One nice thing that I want to mention about </em><em>tmux in particular, is that it is available on most platforms so you can count on it being a quick install away anywhere you need it.</em></p><h3>More Reading</h3><p><strong>tmux official repository</strong><br><a href="https://github.com/tmux/tmux">https://github.com/tmux/tmux</a><br><em>Check this out if you are curious about the </em><em>tmux implementation or are interested in recompiling the code yourself</em></p><p><strong>tmux resource repo</strong><br><a href="https://github.com/rothgar/awesome-tmux">https://github.com/rothgar/awesome-tmux</a><br><em>List of helpful links, tutorials, and resources</em></p><p><strong>The tao of tmux</strong><br><a href="https://leanpub.com/the-tao-of-tmux/read">https://leanpub.com/the-tao-of-tmux/read</a><br><em>Excellent free book covering more advanced</em><em>tmux features</em></p><p><strong>tmux cheat sheet</strong><br><a href="https://gist.github.com/MohamedAlaa/2961058">https://gist.github.com/MohamedAlaa/2961058</a><br><em>Very handy list of </em><em>tmux shortcuts</em></p><p><strong>A tmux crash course</strong><br><a href="https://robots.thoughtbot.com/a-tmux-crash-course">https://robots.thoughtbot.com/a-tmux-crash-course</a><br><em>Learn more </em><em>tmux basics</em></p><p><strong>A quick and easy guide to tmux</strong><br><a href="http://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/">http://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/</a><br><em>Excellent </em><em>tmux tutorial</em></p><p><strong>VIM Adventures<br></strong><a href="https://vim-adventures.com/">https://vim-adventures.com/</a><br><em>Learn </em><em>vim by playing a game</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6539c8eae2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>