tmux
is a great terminal multiplexer which allows viewing / working-in multiple terminal windows simultaneously on your server (via SSH
for example).
Guide
This guide is not supposed to be an in-depth guide on using tmux
. It's purpose is to highlight only several of the most-useful (according to me) commands that I use often.
Installing tmux
tmux
should be available via your distro's package manager. To install on Ubuntu, simply:
sudo apt-get install tmux
Installing from source
Although your preferred package manager will generally have tmux
, it's version might be a old and not support some of the new features (like changing a pane background colour which is supported from v2.1). This was the case for the version provided on my Amazon Linux install. I chose to install from source instead.
Let's first get some dependencies for the build (example here is on Amazon Linux):
sudo yum install automake libevent-devel sudo yum install git
Installation instructions are provided on tmux
official github repo. Stated here as well:
git clone https://github.com/tmux/tmux.git cd tmux ./configure && make sudo make install
Starting a tmux session
To start a tmux
session:
tmux
To list all detached tmux
sessions:
tmux ls
To re-attach a detached session (session 0 for example):
tmux a -t 0
My .tmux.conf
tmux
can be configured to use your own defined shortcuts. This can be done my saving key bindings and other settings to a .tmux.conf
file in your user home folder (do: nano ~/.tmux.conf
)
Below is my (beloved) .tmux.conf
file:
unbind C-b set -g prefix M-Space # Use Alt-hjkl without prefix key to switch panes bind h select-pane -L bind l select-pane -R bind k select-pane -U bind j select-pane -D # THEME set -g default-terminal "screen-256color" # set inactive/active pane styles set -g window-style 'fg=colour247,bg=colour236' set -g window-active-style 'fg=colour250,bg=black'
Theming colours and Putty
Using the above .tmux.conf
file changes several default key-bindings to:
Command | Command prefix |
---|---|
Split window horizontally | cntrl-alt-n |
Split window vertically | cntrl-alt-m |
Resize pane up | cntrl-alt-Up |
Resize pane down | cntrl-alt-Down |
Resize pane left | cntrl-alt-Left |
Resize pane right | cntrl-alt-Right; |
Zoom current pane (make fullscreen) | cntrl-alt-f |
Switch to above pane | cntrl-alt-k |
Switch to below pane | cntrl-alt-j |
Switch to left pane | cntrl-alt-h |
Switch to right pane | cntrl-alt-l |
Reloading .tmux.conf without restarting tmux
You can reload your .tmux.conf
configuration without restarting (e.g. exiting and starting tmux again) by entering prefix
mode (cntrl+b) and entering:
:source-file ~/.tmux.conf
Exiting
To exit a session you can simply "exit" all open terminals.
You can also detach you session by cntrl-b
followed by d
.
Kill tmux session(s)
To kill a session, first list sessions, first list them, then (killing session 0 example):
tmux kill-session -t 0
References
- https://gist.github.com/MohamedAlaa/2961058
- https://gist.github.com/spicycode/1229612
- https://gist.github.com/limingjie/4975c36d13d0927613e6
- https://github.com/tmux/tmux
Related articles