Tmux is a so called "terminal-multiplexer" and is similar to e.g. screen which allows the user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. About the horizontal and vertical splitting of the terminal window in so-called "Panesβ, different software can also be used, for example, on a real-time basis from which a quick, many-sided overview about processes can be attained.
Also sessions can be terminated ("detach") but can later be executed ("attach") again. Moreover, Tmux can be extended with configuration files (under e.g. ~/tmux.conf) for different purposes which do not exist by default yet.
Installation
Tmux can be installed as an IPFire addon over the console with an:
pakfire install tmux
or over IPFires webinterface via Pakfire
Handling
Since tmux offers a lot of features, it would sprinkle the frame in here to list everything. For a deeper look into this subject several howtos can be found in the internet but may also some ideas in this wiki.
Tmux can be started without further options with a simple:
tmux
Also options can be used to start tmux with special preferences like e.g.:
tmux -2 -f tmux.conf
whereby this command offers 256 colors and an individual configuration file.
Key-codes
The different processing modes can be activated about the so-called "bind-key" which is by Default [STRG] - or [CTRL]-b followed by the respective key-codes (key combination).
Note - The key-code list is by far not complete and you are invited to extend it. It should give only an overview of some useful key combinations to use Tmux.
Section | Bind-Key | Keycode | Resultant sign | Action | Commands |
---|---|---|---|---|---|
INFOs | |||||
[CTRL]-b | [ β ]-Γ | ? | List all keys | list-keys | |
[CTRL]-b | q | q | List pane number and pane size | display-panes | |
[CTRL]-b | [ β ]-. | : | Edit commands in session mode | ||
Session Managment | |||||
[CTRL]-b | s | s | List sessions | choose-tree | |
[CTRL]-b | [ β ]-4 | $ | Rename current session | rename-session '%%' | |
[CTRL]-b | d | d | Detach from current session | detach-client | |
[CTRL]-b | r | r | Reload configuration file | source-file /root/.tmux.conf | |
Windows | |||||
[CTRL]-b | c | c | Create a new window | new-window | |
[CTRL]-b | , | , | Rename the current window | rename-window | |
[CTRL]-b | w | w | List all windows | choose-window | |
[CTRL]-b | x | x | Delete pane or window if one pane is left | kill-pane #P | |
[CTRL]-b | d | d | Dettach from the actual session | detach-client | |
[CTRL]-b | c | c | Add a new window | new-window | |
[CTRL]-b | 0-9 or more | Changes to window with allocated number. 0 is the first window | select-window -t :{NR} | ||
[CTRL]-b | [ β ]-5 | % | Split window horizontally | split-window -h | |
[CTRL]-b | [ β ]-2 | " | Split window vertically | split-window | |
[CTRL]-b | [ β ] | β | Change to pane on the right side | ||
[CTRL]-b | [ β ] | β | Change to pane on the left side | ||
[CTRL]-b | [ β ] | β | Change to pane above | ||
[CTRL]-b | [ β ] | Change to pane below | |||
[CTRL]-b [ESC] | [ β ] | β | Resize active window to the right | ||
[CTRL]-b [ESC] | [ β ] | β | Resize active window to the left | ||
[CTRL]-b [ESC] | [ β ] | β | Resize active window higher | ||
[CTRL]-b [ESC] | [ β ] | β | Resize active window lower |
Example configuration
As mentioned before, Tmux can also be used with a configuration file which can contains a lot of different functions. As a little example, which should give an overview of what it could be possible, the following configuration file ~/.tmux.conf
can be used.
With version 3 comes some configuration directive changes. The configuration below is adapted to Tmux 3.x syntax.
# tmux configuration file
# can takes place for user root under Β΄/root/.tmux.conf .
# As a system wide configuration file in case there are more users on IPFire platform,
# you can also use /etc/tmux.conf
#######################################################################################
#
# set defaults
set-option -g default-shell "/bin/bash"
set-option -g default-command "bash -l"
set-option -g default-terminal "screen-256color"
#
# remap prefix to Control + a instead of the default Control + b to screen like style
set -g prefix C-a
unbind C-b
bind C-a send-prefix
#
# reload config also works while a session, please adapt it to your needs in case of a system wide configuration
bind r source-file ~/.tmux.conf \; display-message "Reload config file..."
#
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
#
# Set scrollback to 10000 lines
set -g history-limit 10000
#
# Status bar
# set color for status bar
set-option -g status-style bg=green,fg=black,dim
# Show host name and IP address on left side of status bar
set -g status-left-length 70
set -g status-left "#[fg=black] #h - #[fg=brightred]#(curl -s https://api.ipify.org) #[fg=brightblack]|"
# Define right statusbar lenght
set -g status-right-length 60
# Show value of logged on users, how much RAM is free and how much HDD space are used in /var.
set -g status-right "#[fg=brightblack]| #[fg=black]Users:#[fg=brightred]#(who | wc -l)#[fg=brightblack] - #[fg=black]Mem:#[fg=brightred]#(free -m | awk '/Mem:/ {print $4}')#[fg=black]MB Free#[fg=brightblack] - #[fg=black]Use:#[fg=brightred]#(df -h | awk '/sda4/ {print $5}')#[fg=black]in /var "
# Center window tabs
set -g status-justify centre
#
# Colorize active pane
set-option -g pane-active-border-style fg=blue
#
## End tmux.conf
The functions are explained a little so you can find may a little easier your own ideas for an individual configuration. Tmux with this configuration file looks similarily like this one:
For further information of the Tmux configuration take a look at the bottom to the 'Additional informations' area.
Bash Script
There is also the possibility to arrange your own script (e.g. as /usr/bin/mux
) which can makes jobs like e.g. attach to existing sessions, call your configuration file on every execution and to arrange your pane and window structure to your own needs. The following example should give an example of that:
#!/bin/bash -
#
# Example script has been taken from ubuntu wiki
# http://wiki.ubuntuusers.de/tmux
#####################################################
# With a little modification
#
SESSION=main
tmux="tmux -f /root/.tmux.conf"
# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
echo "Session $SESSION already exists. Attaching."
sleep 1
$tmux attach -t $SESSION
exit 0;
fi
# create a new session, named $SESSION, and detach from it
$tmux new-session -d -s $SESSION
# Window 0
$tmux new-window -t $SESSION:0
$tmux rename-window 'TrafficCheck1'
# Window 1
$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h
$tmux send-keys -t 0 'iftop' enter C-1
$tmux send-keys -t 1 'mtr 8.8.8.8' enter C-1
$tmux send-keys -t 2 'bwm-ng' enter C-1
# Window 2
$tmux new-window -t $SESSION:1
$tmux rename-window 'TmuxYourself;-)'
$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h
$tmux split-window -d -t 0 -h
# Window 3
$tmux new-window -t $SESSION:2
$tmux rename-window 'IPTraf-ng'
$tmux send-keys -t $SESSION:2 'iptraf-ng' enter C-1
# Select entry window
$tmux select-window -t $SESSION:0
$tmux attach -t $SESSION
## End of tmux script
You can place the script e.g. under /usr/bin, this script expects your configuration file under ~/.tmux.conf. If you name the script e.g. mux, you can execute it by simply type mux into the console or via ssh session. A requirement for this is that this script is executable:
chmod +x /path/scriptname
Mux open up 3 windows in a session with different pane structure and content in it. The first window contains 3 different kinds of software iftop, bwm-ng and mtr. The second window quarters the window and waits for commands. The third window provides iptraf-ng. With the above configuration, the tabs in Tmux status bar but also the different panes are clickable with the mouse.
Note - The terminal.app in OS X systems needs Simbl und MouseTerm for clicking and scrolling the Tmux window, pane and tabs.