<?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 Xiangyu Li on Medium]]></title>
        <description><![CDATA[Stories by Xiangyu Li on Medium]]></description>
        <link>https://medium.com/@yiskylee?source=rss-1d9065f12250------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Xiangyu Li on Medium</title>
            <link>https://medium.com/@yiskylee?source=rss-1d9065f12250------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 16:10:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yiskylee/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[GNU Screen and tmux, which should you choose]]></title>
            <link>https://medium.com/@yiskylee/gnu-screen-and-tmux-which-should-you-choose-de325d32fc2a?source=rss-1d9065f12250------2</link>
            <guid isPermaLink="false">https://medium.com/p/de325d32fc2a</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[screen]]></category>
            <category><![CDATA[tmux]]></category>
            <dc:creator><![CDATA[Xiangyu Li]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 17:22:22 GMT</pubDate>
            <atom:updated>2020-04-25T17:22:22.122Z</atom:updated>
            <content:encoded><![CDATA[<p>Before I started using GNU Screen and tmux, when I needed to train a machine learning model on a remote machine, the following describes the typical steps I had to take:</p><p>I open up a terminal on my local machine, ssh to the remote node, and run the program, which prints out the training progress. So far so good.</p><p>But as it is running, I want to monitor resource usage. So I open another terminal, ssh to the remote machine, and then run top. Looks alright.</p><p>Oh wait, this program also logs some output to a file log.txt, and I want to read it to see what’s going on, so again I open up another terminal, run ssh, and then run tail -F log.txt, awesome.</p><p>Hmm, I also just need to search for a data set in the file system real quick…</p><p>So before too long, my desktop looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbeE-9qFxn2ijFsHAR0RWA.png" /><figcaption>Fig. 1 Running multiple ssh terminal windows</figcaption></figure><p>This might look cool and all, but now you can not put your laptop to sleep, or afford to lose internet connection, as you will lose the current state of your workspace, and have to redo everything. GNU Screen would make this whole frustration go away.</p><h3>GNU Screen</h3><p>GNU Screen is a “terminal multiplexer” that manages multiple terminal windows and saves terminal states in “sessions”. You can attach to a session to continue working on your task, or detach from the session, shut down your local computer, while your program is still running on the remote machine. tmux has very similar functionalities as GNU Screen, but it also has its unique useful features. I will show you how to use GNU Screen and tmux, and compare the two, so you can decide for yourself which one you want to integrate to your everyday workflow. For simplicity, I will refer GNU Screen as Screen for the rest of the article. Although do include “GNU Screen” as the key word in your google search query, as there are so many unrelated results if you just search “Screen”!</p><p>Okay. Say now you want to do the task above that uses five terminals, but using Screen. You can start a new terminal on your local machine, ssh to the remote server, and then just simply type screen. A new window (window 0) starts with some intro to screen, type Enter key to go ahead and you are given an empty terminal window. You can treat this window as your normal terminal, and run the machine learning program. To monitor the resource usage while your program is running, you can simply type Ctrl+a c to create a new window (window 1) and run top here. Typing Ctrl+a c again will create window 2, where you can read the log file. Now that you have three windows open, simply use Ctrl+a p to switch to the <strong>p</strong>revious window and Ctrl+a n to switch to the <strong>n</strong>ext window.</p><p>So far we can only view one window at time, in order to view multiple windows simultaneously, similar to the look of Fig. 1, you can first switch back to windows 0, and then type Ctrl+a | (The vertical bar is the symbol above the backslash key \ on your keyboard). This commands splits your current “region” into two regions vertically — the left region displays window 0, and the right region is empty. Type Ctrl+a Tab to move the cursor to the right region, and from there you can again use Ctrl+a p or Ctrl+a n to map the region to an existing window, or Ctrl+a c to map it to a newly created window.</p><p>Now that you have two vertical regions, you can select either one of them and do either of the two things, split vertically again to have three vertical regions, or use Ctrl+a S to split the window horizontally. With Ctrl+a | and Ctrl+a S, you can split your region up to multiple regions with the layout that best suit your productivity need. Fig. 3 shows an example of a 3-window Screen session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XipIp5-5bm5D7dK3l0Vu7Q.png" /><figcaption>Fig. 3 A 3-window screen session</figcaption></figure><p>By default, Screen is split evenly, to achieve the more customized layout in Fig. 3, you can use Ctrl+a :resize &lt;number&gt;/&lt;percentage&gt;, where you can choose how many &lt;number&gt; of lines you want to display in the current region, or use 30% to render a 3:7 layout.</p><h3>GNU Screen Session Management</h3><p>Say you are done with developing this program and want to take a break, leave the program running in the background, and come back later to it without losing any progress, just type Ctrl+a d to <strong>d</strong>etach from it. This sends you back to the very first ssh terminal, now type screen -ls to list the Screen session that you have just created, which would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*33quZtnbSMva0pt_sKZyeA.png" /></figure><p>10711 is the process id of this Screen session, we will revisit this number later. Now say you want to start a deep learning project that is independent from your machine learning project. You can type screen -S deep_learning_project, where -S names this new Screen <strong>s</strong>ession “deep_learning_project” as you are starting it. Now run Ctrl+a d to detach from this screen session and then run screen -ls to view the two sessions you have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*mxfS-881wXglWUPR1hs5TA.png" /></figure><p>We also can rename session 10711 to tidy things up. First <strong>r</strong>eattach to the session by running screen -r 10711, then run Ctrl+a :sessionname machine_learning_project. Now run Ctrl+a d to detach from it again and then list your sessions by screen -ls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*CemeerQwrmkMonf99lxFdA.png" /></figure><p>You can now use a session’s name to <strong>r</strong>eattach to it by running screen -r machine_learning_project.</p><p>This example illustrates Screen’s windows hierarchy: you now have two Screen sessions, each consisting of multiple Screen windows. A Screen session usually corresponds to an independent project, and the multiple windows present you different facades of the project.</p><h3>tmux</h3><p>tmux is an alternative to Screen. The table below lists the several tmux commands that accomplish the same thing as Screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d51ba959c494e339655bfb36b626a4/href">https://medium.com/media/d0d51ba959c494e339655bfb36b626a4/href</a></iframe><p>The major difference between the two is the “command character”, which is Ctrl+a in Screen and Ctrl+b in tmux.</p><h3>GNU Screen v.s. tmux</h3><p>Now let’s compare Screen with tmux to help you choose one that best fits your workflow.</p><h4>Availability</h4><p>Screen and tmux are quite similar in terms of their functionalities. Since Screen is initially released back in 1993, you should be able to find it on all kinds of machines. tmux, released in 2007, is relatively younger, but as it is 13 years ago, there would be very few cases where you couldn’t find it pre-installed on an OS, or downloadable using the OS’s native package management system, e.g., yum or apt. Therefore, even though Screen is more widely adopted, you should have no problem finding tmux on most systems.</p><h4>Command character conflicting with existing Linux tools</h4><p>The use of Ctrl+a in Screen might conflict with the hotkey in your terminal and GNU Emacs, which brings the cursor to the beginning of the line, while Ctrl+b is used for moving the cursor back by one character. There are two methods of solving this:</p><p>Method 1 — &quot;double typing&quot;:</p><p>Type Ctrl+a a in Screen to accomplish what Ctrl+a accomplishes in a non-Screen environment, Ctrl+b b for tmux.</p><p>Method 2 — key remapping</p><p>In ~/.screenrc, add line:</p><pre>escape ^Qq</pre><p>to map Ctrl+a to Ctrl+q, you can replace q with any letter you want. Read more about how this works at section 14.3 on the <a href="https://www.gnu.org/software/screen/manual/screen.html">Screen man page</a>: <br>To do the same thing for tmux, go to ~/.tmux.conf and add to the file:</p><pre>unbind C-b<br>set-option -g prefix C-q<br>bind-key C-q send-prefix</pre><h4>Windows management</h4><p>tmux wins this category for me and it is the major reason that I never looked back after switching to tmux. The overall experience with tmux is better, as it provides following functions that Screen does not have.</p><p>Pane — an added layer of flexibility</p><p>In tmux, there is an additional layer in its windows management hierarchy — pane, where a session can have multiple windows, and a window can have multiple panes.</p><p>Recall what we did in Screen to split a window, when running Ctrl+a |, you only create two regions, where the left region automatically maps to the current window, and you need to manually map the right region to a window. In comparison, when you split a window in tmux, it automatically creates another “pane”, which leaves you with two panes, both belonging to the same window. This behavior feels much more intuitive.</p><p>Copying string in a split window</p><p>As shown in the figure below, when I am in a split window, it is impossible to use mouse to select and copy some texts off of one of the windows, as the selection would go across the two windows. In Screen, I have to close one window, copy the text, split, and map the window again. tmux, on the other hand, introduces a focus mode, where you can use Ctrl+b z to show just one pane, where you can then select and copy the text, and type Ctrl+b z again to exit the focus mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*MKhqR50kg3Gq6_q84NR7Xg.png" /><figcaption>Switch between more than 2 regions/panes</figcaption></figure><p>When you split your windows in four ways, you need to repeatedly type Ctrl+a Tab in Screen to switch between them, while in tmux, you can use Ctrl+b ArrowKey to select directions.</p><h4>Opening and closing text files</h4><p>There is one annoying thing in Screen: when you open up a long text file and then close it, the texts will remain there in your view, making it hard to see the commands you have typed or the result of a ls before you opened the text file. tmux, on the other hand, mimics what a regular terminal would do.</p><h3>Summary</h3><p>In summary, Screen and tmux are both great tools to make your work easier, and I would recommend tmux as it offers more useful features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de325d32fc2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>