I'm about to get back into using GNU Screen, but I have been hearing people occasionally mention tmux as a better alternative. Does it really offer an alternative to all the features Screen offers, such as activity monitoring in different windows, etc.? What are the pros and cons of each?
8 Answers
Some of the (major) reasons I prefer tmux
over screen
:
- Status bar is much easier to use. You can easily set up different text/styles for current window, windows with activity, etc. and you can put things on the left and right of the status bar, including shell commands that can be run at a specified interval (default 15s).
- Almost any command you can run inside
tmux
can be run from a shell withtmux command [args]
. This makes it very easily scriptable, as well as making it easy to do complex commands. - Much more accurate automatic window renaming. While
screen
sets the title based on the first word of the command, and requires shell configuration to do even that in a shell window,tmux
keeps track of what processes are actually running in each window, and updates the title accordingly. This way you get dynamic renaming with any shell and zero configuration. For example: Let's say you're running Z Shell; the window's name would be "zsh". Now let's say you want to edit some configuration file, so you typesudo emacs /etc/somefile
. While sudo is asking for your password, the window's name will be "sudo", but once you've done that andsudo
launchesemacs
, the title will be "emacs". When you're all done and you exitemacs
, the title will change back to "zsh". This is pretty useful for keeping track of windows, and it can also be especially useful in specific situations, like if you have some long-running process in another window that occasionally prompts you for input usingdialog
; the window name would change to "dialog" when that happened, so you would know you had to switch to that window and do something. - Nicer session handling (IMHO). You can do a lot more with sessions within
tmux
itself. You can easily switch, rename, etc. and you can move and share windows between sessions. It also has a different model, where each user has a server which controls his/her sessions and which the client connects to. The downside of this is that if the server crashes, you lose everything; I've never had the server crash on me, though. tmux
seems to be more actively developed. There are updates pretty frequently, and you can file a bug report or feature request according to this FAQ and get an answer within a few days. However, as pointed out in a comment,screen
's lack of development is mostly because it's stable. It's basically done, not abandoned. That said, if it can't do something now, it probably won't ever be able to, and long-standing issues are less likely to be fixed. (Though, to be fair, vertical splitting is one feature thatscreen
didn't have when I first answered this question and does have now.)
Those are some of the reasons I personally switched from screen to tmux. That's not to say screen doesn't have advantages, but FWIW I can't think of anything I've missed since switching. The other answer by a paid nerd has a more objective list of Pros/Cons, though anecdotally I'll say that I've never had the issues with crashes or missed keystrokes that are mentioned there. (Those could have been OS-dependent. I've only used it on Linux and FreeBSD.)
-
191tmux development is more active because it's new. GNU Screen is almost 25 years old, so they've fixed most of the bugs. May 4, 2011 at 18:31
-
8a paid nerd's comment is a very important qualification of your last point. And the second point as stated is not really a difference as it applies to screen as well unless you can be more specific.– jw013Nov 10, 2011 at 4:31
-
18@a paid nerd: techrepublic.com/blog/opensource/is-tmux-the-gnu-screen-killer/…– sjasAug 10, 2012 at 14:07
-
15
-
5
(Sessions are collections of windows that can be detached and reattached later. Windows may contain one or more panes. For example configs, check out here and here.)
tmux
- Pros
- Can send keys to other panes, kind of like an IDE
- Easy keybindings -- with the right config, you'll feel at home from Vim or Screen
- Vim-ish and Emacs-ish bindings built-in
- Good layout management, a lot like a tiling window manager
- Unicode seems to Just Work with modern terminals
- Some terminal issues fixed with
TERM=tmux
- Cons
Slow -- unsure why, but keystrokes seem laggyNo more issues with slowness- Multiplexing forces the whole session width and height to the smallest attached terminal
- Has crashed multiple times on Mac OS X, losing the entire session
- Has failed on Linux after upgrade, where I couldn't reconnect to my old session
- Misses command keystrokes occasionally - ^A ^[ takes a few tries for copy mode
Can't move a pane from one window to anotherFixed with thejoin-pane
command- No line unwrapping (or "reflow" or "rewrap") after terminal width change (window resizing)
GNU Screen
- Pros
- Extremely stable (v1.0 was in 1987)
- Some terminal issues fixed with
TERM=screen
- Emacs-ish bindings built in
- Easy to move and control horizontal panes
- When multiplexing, any attached terminal can resize a pane
- Cons
No vertical splits without patch (except on Ubuntu)More recent releases of screen support vertical splitsPane splits are lost when detachingFixed with the layout save default command- Getting Unicode to work takes a little finesse and determination
- Complex and confusing status line configuration
-
Are the laggy keystrokes only when pressing Esc? tmux has a delay where it waits to see if you're entering an xterm sequence or just a lone Esc, and combined with vim's, it can seem pretty laggy. Set escape-time to a lower value like 50.– EeveeJun 4, 2011 at 21:37
-
It's also funny you say
^A ^[
doesn't work sometimes; I have the same problem with screen, but never tmux! And I believe you can move panes around withjoin-pane
.– EeveeJun 4, 2011 at 21:38 -
8Well,
tmux
sucks withvim
, in some cases (mine namely), no solution ever posted anywhere works, and even people spending some time solving the issue of mine weren't able to. It's annoying when you can't use<C-Left>
and<C-Right>
invim
.– yo'Feb 19, 2014 at 10:14 -
4
No vertical splits without patch (except on Ubuntu)
I don't think that is true. I've been using screen for a few years now and I never had any issues splitting horizontally or vertically on Debian and Fedora. Even on Android with Termux it works like a charm.– ForivinApr 18, 2018 at 15:54 -
1@Forivin The previous comment was made in 2014 when screen 4.2 had not yet been released.– N MJul 25, 2018 at 9:32
A pro for screen: it is available pretty much out-of-the-box on Linux and Solaris. When you have to switch back and forth between platforms, it is nice not to have the mental context switch.
I'm sure you can get tmux compiled on any platform, but sometimes you have just enough access to make use of screen, but the actual system admins don't really want to add any software that isn't absolutely necessary.
-
3RHEL / Centos 8 has dropped GNU Screen. Still in Ubuntu 20.04 LTS though.– sastorslAug 25, 2020 at 20:01
-
3Thank you, @sastorsl . This page has some additional information and interesting commentary: access.redhat.com/solutions/4136481– JustinAug 26, 2020 at 15:51
I've been using tmux
for about 2 days now, so my unbridled enthusiasm for it has not yet been tempered by hitting annoying use cases.
While going through the usual growing pains of transitioning from one program to another, I was struck by several positive features, but the feature that has me believing I'll never go back to screen is the utility of the copy-n-paste mode.
In screen
, you cannot enter copy mode, scroll back in the buffer, and then go to another window.
In tmux
, you can have multiple windows simultaneously in copy mode with the buffer scrolled back to different positions. Also, there are multiple copy buffers. And you don't need to patch the source to get fFtT cursor movement.
-
6"In screen, you cannot enter copy mode, scroll back in the buffer, and then go to another window." Maybe this has changed since 2012, but I just tried this and it works fine.– cdhowieOct 12, 2019 at 23:15
I have replaced GNU Screen with tmux in every use case except one—when I need a HyperTerminal equivalent to connect to serial ports. As Aaron Toponce noted in his article "Connecting To Serial Null Modems With GNU Screen", the tmux FAQ states:
screen has builtin serial and telnet support; this is bloat and is unlikely to be added to tmux.
My typical tmux use-case is to create multi-pane and multi-window development sessions in combination with tmuxinator. If you want to learn tmux, I recommend getting Brian P. Hogan's book, tmux: Productive Mouse-Free Development.
-
4Do you know
cu
Call up another system ? Simplier serial tty than screen, but light and usefull! Apr 10, 2019 at 9:39
I've been a heavy user of Screen for a long time, but I use a version that I modified back in 2002. Mostly because I wanted to be able to have the window "next/prev" navigational ordering match the order in which new windows were created, similar to a tiling window manager like i3 or Ion. The standard Screen behavior is for 'next' and 'prev' to go by window number, so that usually a 'new' window (grabbing the smallest available number) will be located elsewhere than the 'next' window - confusing if you don't remember the numbers. My preferred behavior has since been implemented in Tmux as a flag to the new-window command in 2010, and the renumber-windows option in 2012. My Screen patch, which I tried to make as acceptable as possible, including documentation additions and so forth, did not generate any discussion on the Screen list in July 2002 (then "screen@informatik.uni-erlangen.de", can't find archives). In fact it was not even acknowledged, even when I sent it again a year later.
Since 2002, I "rebased" my patch a couple of times to apply to newer versions of Screen. However, when I got to version 4.3 (2015) I noticed an undocumented change which broke one of my uses of screen - namely that 'stuff' now interpolates environment variables. I didn't need that feature, and I couldn't figure out how to easily escape the argument to 'stuff' (so that I could send text containing dollar signs) so I just kept using version 4.0 (from 2004).
I use Screen's 'stuff' ('send-keys' in Tmux) in an Emacs function which sends the contents of the current Emacs region to a specific window number. That way when I am writing code in a scripting language, I open an interpreter, I give the intepreter window a special number, and then I can send lines of code from my editor window directly to the interpreter window using this Emacs binding. It's hacky but I like it better than the pure-Emacs solution, since I can also interact with the interpreter in its Screen window using standard keystrokes. It's a bit like a GUI IDE, but I don't have to use the mouse or stare at a blinking cursor.
Another feature I implemented in my patch is the ability to "mark" a window, and then to reposition the marked window to be "next" after the current one. For me this is a much more natural way of reordering windows than renumbering; it is like the copy/paste paradigm, or "drag-and-drop". (I recently figured out how to do this in i3 as well.)
It should be possible to do the same thing in Tmux, for example as of 2015 there is a facility for "marking" a pane. Or perhaps a more elementary solution could be worked out with stateful shell scripts. I implemented a short script and keybindings to try the "marked pane" method, and it worked a few times but then Tmux crashed with "[lost server]". Then I found Tmux crashing even without my trying to do anything complicated. Apparently it has been crashing for some users for a few years at least. Sometimes the server crashes, sometimes it starts using 100% of the CPU and becomes unresponsive. I've never seen Screen do either of these.
In theory, Tmux is superior to Screen in several ways. It has much better scriptability, meaning that you can do things like query the list of windows in the current session from the command line, which is impossible with Screen. For example in 2015 Screen added a command to "sort windows by title". I'm not sure when such a specialized command would be useful, but this and more practical variations (e.g. sort windows by CPU usage) could relatively easily be done from a shell script in Tmux. To me it would seem difficult to do anything so creative in Screen, at least without modifying the C code.
As other posters mentioned, Tmux has a single-server model which I see as the primary drawback, particularly when the server is crashing. It is possible to work around this by specifying a separate socket for each "session". Still I prefer Screen's one-server-per-session default, which seems slightly more elegant.
Working with the Screen code, back in 2002, was educational and enjoyable for me. Oddly enough, for all its additional features, Tmux has about 25% fewer lines of code than Screen (30k vs 40k). I noticed that Tmux uses many tree and list data structures, which were slightly difficult for me to understand. Screen seemed to prefer arrays.
As I understand it, because the Unix terminal interface is so stable, there is little need for the Screen or Tmux code to adapt to changes in the underlying operating system. These programs do not really have security updates like web browsers or web servers or even the shell. I haven't noticed any problems running my custom version of Screen, last updated in 2004 (except for needing to add some configuration files to prevent Systemd from deleting the socket; these files are typically part of the distribution package anyway). Perhaps I could just work around the problems I encountered in Tmux by running a Tmux version from before it started crashing. Of course, if enough users do this then it won't be very good for new users, since it means that fewer experts will be looking for bugs in the latest official versions of these programs. However, it's hard to motivate myself to switch to a product which is unstable for me (latest Tmux) or which lacks certain features that I want (standard Screen).
I know this doesn't provide an easy answer to the OP's question, but I hope that my perspective was useful.
-
Nobody has asked for it, but here is the patched version of Screen that I use, based on the official release of 2003, in case it may be useful. github.com/navarum/tweaks/blob/master/screen/CHANGES.md Mar 6 at 20:04
The things I get out of tmux I don't get easily in screen are:
- make vertical pane splits
- multiplexing, which we use for remote and local pairing.
-
9
-
As previous post mentions, screen has vertical pane splits (requires a patch w/o Ubuntu, apparently). Also, multiplexing works fine and has for many years. Jan 27, 2017 at 16:25
-
4vertical splits have been in mainline
screen
since 4.2, released in 2014. Many distros ship very old versions, especially Apple. May 3, 2017 at 6:07 -
3
-
4
I would say that screen’s availability is its strength, but its windowing system is not as easy to handle as tmux’s. I must say I use gnu-screen most of the time at present and as a result have plenty of terminal tabs instead of Screen windows.
@Jed Schneider: You can get vertical pane splits with Ctrl+A and then | (vertical bar).
screen -S automate_me -X stuff 'command'$(echo -ne '\015')
you can't in tmux. Pretty useful if you're testing a virtualbox ISO/image and need to do some commands remotely quickly. For example I have it in a Vim command to quickly debug scripts in a Virtualbox screen. In earlier versions of tmux I found that screen handled more text passing by quickly whereas tmux crashed. Also screen doesn't require any configuration to handle UTF-8 etc. tmux does.tmux
handlehistory
properly?mosh
which is great for flakey connections and can wrap a tmux or screen.