tmux – the terminal multiplexer

Tmux, short for terminal multiplexer, is a utility which allows for the creation and use of multiple terminal sessions with a single window. A user can easily manage multiple tasks and command line programs on a Linux server, without the clutter of many open windows. Sessions can be detached, attached and shared, staying in the background.

Tmux is very similar to GNU Screen, but with some additional advanced features, and is more regularly maintained.

Using tmux

To start a tmux session, simple execute the command.

$ tmux

You’ll then be under a new shell, in the initial tmux window. At the bottom, you’ll see a green bar which lists this session’s windows.

  1. To create an additional window, execute the keystrokes “Ctrl+b” then “c”. A new window will be created (window 1), and you’ll be placed at that prompt.
  2. To list and move between windows, execute “Ctrl+b” + ‘w’.
  3. Closing a window simply involves exiting the shell; with the ‘exit’ command or press “Ctrl + d”.

“Ctrl+b” is the binding key or prefix key stroke. It will need to be executed before any other.

For a complete listing of the available key bindings, execute “Ctlr+b” + “?”.

Detach and Resume Session

To detach a tmux session, issue the keystrokes “Ctrl+b” + “d”. You’ll then leave the tmux session, and be brought to your original prompt.

To resume a session, run the command:

$ tmux attach

If you have multiple tmux sessions running, you’ll need to identify the desired session, and then attach with the ‘-t’ flag.

$ tmux ls
0: 1 windows (created Fri Jul 13 00:47:46 2011) [113x20]
1: 1 windows (created Fri Jul 13 00:49:12 2011) [113x20]
$ tmux attach -t 1

 

iterm Integration

Alias on the remote server

alias tmux='LANG=en_US.UTF-8;tmux -CC attach || tmux -CC'

LANG is introduced as it was set to just en_US and tmux complained of not being in UTF-8 mode.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *