tmux

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. It lets us split our terminal into panes, switch between different sessions, and keep programs running even when we disconnect.

Architecture overview of tmux

Figure: Architecture of tmux emphasizing the several interfaces available to the user.

Sharing a tmux session

A user should first create/launch a new session with a chosen socket file name (for instance group-session)

[user1@mc2]$ tmux -L group-session

This will create a socket file /tmp/tmux-<UID>/group-session, where UID is user1 ID number. Make the socket directory and file group-readable, writable and executable:

[user1@mc2]$ chmod -R 770 /tmp/tmux-`id -u`
[user1@mc2]$ ls -la /tmp/tmux-`id -u`
total 16
drwxrwx---   2 user1  users  4096 Sep 18 09:25 .
drwxrwxrwt. 15 root   root  12288 Sep 18 09:31 ..
srwxrwx---   1 user1  users     0 Sep 18 09:25 group-session

The socket can be used as a handle for a second user who wishes to have real-time access to the session. If the UID of user1 is 1039, that second user should type:

[user2@mc2]$ tmux -S /tmp/tmux-1039/group-session attach

Session Control

Commamd Description
tmux
tmux new -s <session-name> Start a new session with a chosen name
tmux ls List all sessions
tmux attach -t <session-name> Re-attach a detached session
tmux kill-session -t <session-name> Delete session

Copy Mode

Short-cut Description
Crtl+b, [ Enter copy mode
Crtl+b, G Bottom of history
Crtl+b, g Top of history
Crtl+b, Enter Copy selection
Crtl+b, p Paste selection
Crtl+b, k Cursor up
Crtl+b, j Cursor down
Crtl+b, h Cursor left
Crtl+b, l Cursor right

Window Control

Short-cut Description
Crtl+b, c Create new window
Crtl+b, d Detach from session
Crtl+b, , Rename current window
Crtl+b, & Close current window
Crtl+b, w List windows
Crtl+b, p Previous window
Crtl+b, n Next window

Pane Control

Short-cut Description
Crtl+b, " Split pane horizontally
Crtl+b, % Split pane vertically
Crtl+b, o Next pane
Crtl+b, ; Previous pane
Crtl+b, q Show pane numbers
Crtl+b, z Toggle pane zoom
Crtl+b, ! Convert pane into a window
Crtl+b, x Kill current pane
Crtl+b, Ctrl+0 Swap panes
Crtl+b, t Display clock
Crtl+b, q Transpose two letters
Crtl+b, { Move to the previous pane
Crtl+b, } Move to the next pane
Crtl+b, Space Toogle between pane layouts
Crtl+b, Resize pane - make it taller
Crtl+b, Resize pane - make it shorter
Crtl+b, Resize pane - make it wider
Crtl+b, Resize pane - Make it narrower

Plugins

Short-cut Description
tmux resurect https://github.com/tmux-plugins/tmux-resurrect
Crtl+b, Ctrl+s Save current environment
Crtl+b, Ctrl+r Restore (saved) environment