Infrastructure at your Service

You may already use screen for multiplexing a terminal. This is especially useful when you want to start long running processes on a server and do not want to loose the connection because of a ssh connection timeout, firewall settings or other reasons. With screen the session keeps running even if you got disconnected somehow and you may re-attach to the screen session at any point later.

In this post I want to make you aware of another tool that does the same thing. It is called tmux and available for the most Linux/Unix platforms. Installation is straight forward and easy:

For debian based distributions:
apt-get install tmux

For redhat based distributions:
yum install tmux

Imagine you have an oracle database running on a server and you want to perform several tasks without the risk of loosing the connection. With tmux this becomes very easy:
Open a new tmux session:
tmux

You will be immediately connected to it. In this session do whatever you want, e.g. tailing the oracle alert.log: Selection_066.pngSelection_067.png
In another session you now want to do a restart of the database. In tmux you can horizontally split the screen by hitting
CTRL-B ”

on the keyboard. Now you can do the restart of the database and watch the alert.log in the same session: Selection_068.png
Lets say you now want another screen for running top. No problem: Hitting
CTRL-B %

will split the screen vertically and you can now run top:
Selection_069.png

You can add as many screens as you want. Cycling through the screens is done by
CTRL-B

and one of the up/down/left/right arrow keyboard keys. Detaching from the screen is done by
CTRL-B d

Selection_070.png

For re-attaching just type:
tmux attach

… and everything will be back.
Selection_071.png
The man page for tmux is here.

One Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Daniel Westermann
Daniel Westermann

Principal Consultant & Technology Leader Open Infrastructure