tmux vs. GNU Screen
Browsing through questions I found about tmux (I normally used GNU Screen). My question is what are pros and cons of each of them. Especially I couldn’t find much about tmux.
tmux is fairly new compared with GNU screen. Advantages / Disadvantages is a tough question, as both programs solve approximately the same problem. tmux is BSD licensed while screen is GNU GPL. This matters to some people.
screen is more represented (on Linux) at the moment, that is, you are more likely to find it on a given linux box than tmux. tmux is however more represented on OpenBSD as it is included as part of the base install.
Both programs allow you to do about the same thing, though the state of things is a bit more complex than that. Switching between the two is not overly complicated, as much of screens functionality has also found its way into tmux, though if you are a power user of either one, you will likely find some frustrations when switching to the other.
As with any program, it really depends on your needs, and which you are more comfortable with. Give them both a try and see which you play nicely with.
For more info on tmux see https://tmux.github.io/
The biggest difference in my use has been that in Gnu Screen you can only split frames horizontally, whereas in Tmux you can split both horizontally and vertically. This is kind of a moving target, though as I here tell that vertical split is making it’s way into screen.
Other then that, things are about flat.
I had troubles getting screen to support utf-8 and 256 colors but tmux worked out of the box.
From their website:
- How is tmux different from GNU screen? What else does it offer?
tmux offers several advantages over screen:
- a clearly-defined client-server model: windows are independent entities which
may be attached simultaneously to multiple sessions and viewed from multiple
clients (terminals), as well as moved freely between sessions within the same
tmux server;- a consistent, well-documented command interface, with the same syntax
whether used interactively, as a key binding, or from the shell;- easily scriptable from the shell;
- multiple paste buffers;
- choice of vi or emacs key layouts;
- an option to limit the window size;
- a more usable status line syntax, with the ability to display the first line
of output of a specific command;- a cleaner, modern, easily extended, BSD-licensed codebase.
There are still a few features screen includes that tmux omits:
- builtin serial and telnet support; this is bloat and is unlikely to be added
to tmux;- wider platform support, for example IRIX and HP-UX, and for odd terminals.
One difference is in how the two act when multiple terminals are attached to a single session.
With screen, each attached terminal’s view is independent of the others. With tmux, all attached terminals see the same thing.
Say you have two terminals attached to a single tmux session. If you type ^B 1 into one terminal, the other terminal also switches to window 1.
When you have two terminals attached to a single screen session, and you type ^A 1 into one, it has no effect on the other terminal.
This is based on my experience with tmux 1.2; I see 1.3 is out but I didn’t notice anything in the changelog about this behavior changing.
If you like the screen behavior and want it in tmux:
If your original tmux session is called 0
(the default), then you can do tmux new-session -t 0
) to start up a new independent session connected to the same set of windows, which can then have its own view.
I will take the liberty of adding one difference:
tmux is ncurses based while screen does not draw additional elements. If someone use terminal emulator that supports scrolling (s)he will get scrolling with screen but not with tmux (at least in default configuration). The same thing applies to searching and similar features.
Drench raises an interesting point – the default behavior of connecting twice to the same session is different in tmux. However, if you want to attach twice and have an independent view of the windows in that session – start tmux with
tmux new-session -t <session name>
That will create a new session for you, and attach the windows from the already existing session. If you didn’t name your first session, you can add one with ‘rename-session’.
I thought I would just mention about the byobu
wrapper that is available for screen that makes it so much better right out of the box. I don’t know if something like this is available for tmux, but byobu
made my .screenrc only a handful of lines. Check out this quick article about byobu and screenshots. The project page for byobu describes the name originating from a Japanese term for decorative, multi-panel screens that serve as folding room dividers. Also, just running it doesn’t harm your screen settings, so you can safely try it. Once you start the session with byobu
you can freely reconnect to it using screen
and still not loose any customizations done by byobu
(so use it only for the initial invocation). The two main advantages of it are:
- Starts screen with a couple of status bars with useful information
- Provides many keybindings to access screen’s functionality easier
I am not using the keybindings part, but definitely find the status bars useful.
Also you might find Screen Vs tmux link useful. I think most of it is already mentioned by existing answers.
tmux is newer and several more features.
I have found that good use depends on good setup.
I use vi(vim) for editing (ruby on rails) and there’s a few setup things to make that work well.
Here’s my ~/.tmux.conf file with lot of helpful setting:
bind r source-file ~/.tmux.conf ; display "Reloaded!" # Reload with ctrl-r
set -g prefix C-a # prefix from ctrl-b to ctrl-a
unbind C-b # allow ctrl-b for other things
set -sg escape-time 1 # quicker responses
bind C-a send-prefix # Pass on ctrl-a for other apps
set -g base-index 1 # Numbering of windows
setw -g pane-base-index 1 # Numbering of Panes
bind split-window -h # Split panes horizontal
bind - split-window -v # Split panes vertically
bind h select-pane -L # Switch to Pane Left
bind j select-pane -D # Switch to Pane Down
bind k select-pane -U # Switch to Pane Up
bind l select-pane -R # Switch to Pane Right
bind -r C-h select-window -t :- # Quick Pane Selection
bind -r C-l select-window -t :+ # Quick Pane Selection
bind -r H resize-pane -L 5 # Switch to Pane Left
bind -r J resize-pane -D 5 # Switch to Pane Down
bind -r K resize-pane -U 5 # Switch to Pane Up
bind -r L resize-pane -R 5 # Switch to Pane Right
setw -g mode-mouse off # Mouse Off
set -g mouse-select-pane off # Mouse Off
set -g mouse-resize-pane off # Mouse Off
set -g mouse-select-window off # Mouse Off
setw -g monitor-activity on # Activity Alerts
set -g visual-activity on
set -g status-fg white # Status line Colors
set -g status-bg black
setw -g window-status-fg cyan # Window list color
setw -g window-status-bg default
setw -g window-status-attr dim
setw -g window-status-current-fg white # Active Window Color
setw -g window-status-current-bg red
setw -g window-status-current-attr bright
set -g pane-border-fg green # Pane colors
set -g pane-border-bg black
set -g pane-active-border-fg white
set -g pane-active-border-bg yellow
set -g message-fg white # Command/Message Line.
set -g message-bg black
set -g message-attr bright
set -g status-left-length 40 # Status Line, left side
set -g status-left "#[fg=white]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
set -g status-utf8 on # Status Line, right side
set -g status-right "-------"
set -g status-interval 60 # frequency of status line updates
set -g status-justify centre # center window list
setw -g mode-keys vi # vi keys to move
unbind v # Open panes in same directory as tmux-panes script
unbind n
bind v send-keys " ~/tmux-panes -h" C-m
bind n send-keys " ~/tmux-panes -v" C-m
unbind Up # Maximizing and Minimizing...
bind Up new-window -d -n tmp ; swap-pane -s tmp.1 ; select-window -t tmp
unbind Down
bind Down last-window ; swap-pane -s tmp.1 ; kill-window -t tmp
bind P pipe-pane -o "cat >>~/#W.log" ; display "Toggled logging to ~/#W.log"
One big con for screen
is that it is not actively developed. The bug pages have close to 200 unassigned items going back over 5 years.
tmux
has some open issues as well, but far less, and is more actively supported.