tmux cheatsheet
1 tmux or terminator
First of all tmux is widely available and lightweight, but terminator may be a preferred choice. But for the remainder of this doc discusses tmux
2 tmux, the terminal multiplexer
tmux is a sysadmin tool for managing remote servers. It is run on a remote
server, and then used on the remote server
.
A typical use case is as follows:
ssh
to a remote serverstart
a tmux session and start a process within that tmux session.dettach
the tmux session- close the ssh session and
logoff
- go home, watch a movie, let time elapse
ssh
to the remote server from the same or different source sitere-attach
tmux session and continue the process started in 2)
3 tmux architecture
tmux is architected on three concepts,
- 1. sessions Running
tmux
starts a session,that is separate from theterminal
orssh
process, which can then be detached, (^ad
) and re-attached from a new location. - 2. windows (can think of it as tabs)
- 3. panes (think of it as splitting your window into multiple window panes)
3.1 Session
A single collection of pseudo terminals
under tmux control. See tmux sessions
3.2 Windows
You can have one or more windows
to a session
. Each window is a pseudo
terminal
.
3.3 Panes
Each window
can be split into panes
, each of which are a pseudo terminal
3.4 permanence
a tmux session will survive a disconnection from the network. To re-attach to
that tmux session use tmux attach
or tmux -a
3.5 A session is displayed on screen by a client.
3.6 All sessions are managed by a single server
The client and server are separate processes that communicate through
a socket in /tmp
3.7 ~/.tmux.conf
.tmux.conf
is a set of tmux commands which are executed in sequence when the
server is first started. If you want to reload the config file later one
can use the "source ~/.tmux.conf
" command later.
4 tmux [-c show-command] [-f file] [-L socket-name] [-S socket-path] [command[flags]]
When tmux is started
in creates a new session
with a single window and
displays it on the screen.
4.1 options (I will use the defaults for now)
4.2 override the .tmux.conf file
-f file
: to specify an alternative tmux configuration file, over-riding
the usual ~/.tmux.conf
5 tmux key bindings
An attached client can control tmux through a key combination of a prefix key
followed by a command key. The default prefix-key is C-b
C-b <command>
C-b <command>
C-b <command>
5.1 key-bindings for WINDOW controls:
Usual key bindings are as follows:
C-b prefix i.e. so you can C-b <command>
to run a tmux command.
C-z suspend tmux client
So all of these next commands use C-b prefix first
, followed by the letter or
symbol. For example C-b w
to list all the w
indows.
&
kill current window
# force kills all processes in unresponsive window,
rename current window
. ~prompt for an index
to move the current window:
enter the tmux command prompt : often used tosplit-window horizontally
=
choose which buffer topaste
interactively from a list[
enter copy mode to copy text or history]
paste the buffer of text- c
create new window
- n move to
next
window * one of my favs as b and n are side by side i.e.C-b n
cycles through the open windows. p
move toprevious
windowl
move topreviously selected
window- w
which
window (lists them all) * another of my absolute favs i.e.C-b w
then use arrow keys to peak at all the windows.hammer
to select 0-9
select window
0 to 9f
search
for text in open windowsi
info- exit
closes
a window
EOF C-d
closes
the window if on the last remaining window
Called "shut" by some. or EOF by others.
5.2 key-bindings for PANE controls:
C-b
prefixC-z
suspend tmux client\C-o
rotate the panes in the current window!
break
the current pane out of the window"
split
the current pane into two,top
andbottom
- %
split
the current pane into two,left
andright
think of the / in the % as the vertical split line. #
list all pane buffers$
rename current session;
move
to the previously active pane_- o
next pane
in current window * q
briefly display pane indexes i.e. where am I?{
swap current pane withprevious
- -
}
swap current pane withnext
- : enter the tmux command prompt : often used to "split-window" horizontally
so
C-b : split-window
=
choose which buffer to paste interactively from a list[
enter copy mode to copy text or history]
paste the buffer of textm
mark current paneM
clear mark- x kill current pane
z
toggle zoom state of current pane i.e. zooms into the window then back out again. I use this lots.- arrows
change
to a pane# popular usage to switch window focus
- alt-arrows
resize
current pane M-1 to M-5
use preset pane layoutsspace
to cycle through the above preset pane layouts
- : enter the tmux command prompt : often used to "split-window" horizontally
so
EOF C-d
closes
the pane you are on.
Called "shut" by some. or EOF by others.
6 tmux sessions
tmux allows you to dettach from your current active session, but leave the processes running in the background. You can then re-attach to a session from a different location, at a later time, or both.
Running tmux
opens a new session. That session can be suspended (^ad
) for detach
and then
reattached with tmux a
for attach.
6.1 tmux session commands
These commands are run from the bash shell
, before you start a tmux session.
So, for example to create a session and call it "backup-session" presumably
to run some back-up job that could take a couple of hours, you can type:
tmux new -s backupsession
where -s allows you to name the session from the next string argument, in this case "backupsession".
Then if you close the session, it will
C-b d
is dettach
from the session. The session will survive even a logout.
- tmux ls
tmux attach -t 0
Tore-connect
to a previously dettached sessiontmux a
also works with the last attached session.tmux attach -t backupsession
Tore-connect
to a named session- tmux detach-session
- tmux new -s batch-jobs-for-payroll
tmux new -t editing-configs
- tmux kill-session batch-jobs-for-payroll
- tmux list-clients
tmux list-sessions
What sessions have Ipreviously dettached
.- tmux list-commands
- tmux suspend-client
- tmux switch-client
tmux list-commands
- tmux kill-server
6.2 key-bindings for session controls:
- ~C-b
prefix for all of these controls too.
- ~
(
switch the attached client to the previous session)
switch the attached client to the next session:
enter the tmux command prompt : often used to "split-window" horizontally=
choose which buffer to paste interactively from a listD
choose a client todetach
L
switch the client attached back to the Last session
- ~ d
detach
the current clientr
redraw attached clients
select a session for the attached client interactively
C-d
is a usual "end of inpu:dt
" command that when entered in a pane, closes that shell, and then because there is no more shell, closes the pane too Called "shut
" by some. orEOF
by others.
I find myself using C-b-)
a lot. Just cycle through my sessions.
6.3 commands
tmux list-sessions
sessions, windows and panes are each numbered with a unique ID. sessions IDs are prefixed with a $ (ding) windows are prefixed with a @ (at) panes are prefixed with a % (mod)
6.3.1 attach-session
6.3.2 detach-session
6.3.3 kill-server
6.3.4 kill-session
6.3.5 list-clients
(all clients attached to the server)
6.3.6 list-commands
6.3.7 list-sessions
6.3.8 new-session <session-name>
the new session is attached to the current terminal, unless use -d
6.3.9 refresh-client
6.3.10 start-server
Start the tmux server, if not already running, without creating any sessions
6.3.11 suspend-client
6.3.12 switch-client
7 tmux sessions
tmux new -s batch-job-session
8 example tmux session
ssh
into remote server
tmux
# to start the server
C-b c
# to create a new window
C-b &
# to kill a window
-——— windows ————
C-b ,
# to give the window a better name
C-b p
C-b n
# to jump to previous or next window
C-b w
# list windows
-——— now panes ———
C-b %
# to split the window into 2 vertical panes
C-b o
# to swap to next pane.
C-b o
# to swap to next pane.
C-b o
# to swap to next pane.
C-b x
# to kill a pane
–——— sessions————
tmux new -s batch-jobs-session
C-b d
# detach from the current session altogether.
ps aux | grep htop
# to prove that the process is still running.
close the ssh session, shutdown your macbook, and go home.
ssh back into the remote server
tmux list-sessions # should show you the session you created earlier.
tmux attach -t batch-jobs-session
9 Another cheat sheet for tmux
From is a cheat sheet:
tmux ls (or tmux list-sessions) tmux new -s session-name C-b d Detach from session tmux attach -t [session name] tmux kill-session -t session-name
C-b c
Create new window
C-b d
Detach current client
C-b l Move to previously selected window
C-b n
Move to the next window
C-b p Move to the previous window
C-b &
Kill the current window
C-b ,
Rename the current window
C-b q Show pane numbers (used to switch between panes)
C-b o
Switch to the next pane
C-b ? List all keybindings
C-b n
(Move to the next window)
C-b p (Move to the previous window)
C-b l
(Move to the previously selected window)
C-b w
(List all windows / window numbers)
C-b 3
window number (Move to the specified window number, the
default bindings are from 0 – 9)
C-b %
(Split the window vertically)
C-b "
(Split window horizontally)
C-b o
(Goto next pane)
C-b q
(Show pane numbers, when the numbers show up type the key to go to that pane)
C-b {
(Move the current pane left)
C-b } (Move the current pane right)
C-b : "break-pane"
bind | split-window -h bind - split-window -v
##########################
10 all command key bindings together (i.e. C-b _ where _ is: )
C-b
prefixC-o
rotate window panes forwardC-z
suspend tmux client!
break the current pane out of the window"
split the current pane into two, top and bottom%
split the current pane into two, left and right#
list all pane buffers&
kill current window$
rename current session,
rename current window(
switch the attached client to the previous session)
switch the attached client to the next session.
prompt for an index to move the current window0
-9 select window 0 to 9:
enter the tmux command prompt : typically used to "split-window" horizontally:
shut to close the window;
move to the previously active pane=
choose which buffer to paste interactively from a listD
choose a client to detachL
switch the client attached back to the Last session[
enter copy mode to copy text or history]
paste the buffer of textc
create new windowd
detach the current clientf
search for text in open windowsi
infol
move to previously selectec windown
change to next windowo
next pane in current windowp
previous windowq
briefly display pane indexesr
redraw attached clientm
mark current paneM
clear marks
select a session for the attached client interactivelyw
which window lists them allx
kill current panez
toggle zoom state of current pane{
swap current pane with previous}
swap current pane with next
arrows change to a pane M-1 to M-5 use preset pane layouts space arrange current window in next pane layout