User Tools

Site Tools


tmux

If you want to send us your comments, please do so. Thanks
More on comments


tmux

tmux is a terminal multiplexer

Hierarchy: server - client - session - window - pane

Session names

Underscores

Underscores at the end of the session name are ignored and do not have to be entered when entering a session name. This is useful to have a nice table when doing tmux list-sessions
Even better, everything after the first underscore is ignored and does not have to be entered when the session name is used. Example: A name of a session is: host_____t5 . Command: tmux attach -t host attaches session named host_____t5

Some commands

  • All commands starting with tmux must be ran in a normal terminal (not in a tmux session / window)
  • In a tmux session: C-b stands for CTRL-b. All keybinding enteries need to be started with C-b unless otherwise noted
  • The tmux commandline (in a tmux session / window) can be opened the the C-b : command. It has a scrollback buffer
    • All commands without tmux or C-b in front of it must be ran from the tmux commandline
CommandKey-bind-ingExplanationRemark
Help commands
tmux list-commands List the commands
tmux list-keys List the default keybindings
Other commands
tmux list-clients
tmux new-session Start a new session. This has to be done before any other tmux commandJust tmux or tmux new can also be used
tmux new-session -s sessionname Start a new session and give it a name
?List all keybindings
:Show the promptOn the prompt line you can enter textual commands. See the “Command” column
$Change the session nameUnderscores at the end of the session name are ignored and do not have to be entered when entering a session name. This is useful to have a nice table when doing tmux list-sessions
tmux list-sessionssList sessionsQ to exit the list. This command also works in an other, non tmux terminal on the same computer. tmux ls can also be used
tmux detach-client -t /dev/pts/12 Detach /dev/pts/12List with tmux list-clients
tmux detach-client -s sessionname Detach a session
dDetach sessionThe process in the session keeps running
tmux attach -t sessionname Bring a detached session in viewUnderscores at the end of the session name are ignored and do not have to be entered when entering a session name.
tmux new-windowcOpen a new window. On the status bar two windows are now mentioned
wList windows
fFind windowExecute with ENTER
,Change the window name
1Change to window 1Other digits change to other active windows
nChange to the next window
pChange to the previous window
tmux split-window -vSplit the window (or pane) vertically into two panes (a horizontal line in the middle)
tmux split-window -h%Split the window (or pane) horizontally into two panes (a vertical line appears in the middle of the window)
tmux split-window -v -p 20 Split the window (or pane) horizontally into two panes (a vertical line appears at 20% of the bottom of the window / pane)
tmux split-window -h -p 20 Split the window (or pane) horizontally into two panes (a vertical line appears at 20% of the right side of the window / pane)
move-window -s 2 -t 4 Move window 2 to position 4
&Kill windowYou drop out of tmux. If there are other sessions open you can get back to them by running tmux attach
tmux a Attach the detached sessiona can be replaced with “attach”
tmux a -t sessionname Attach session sessionname
break-pane Make a window from a pane
display-panesqDisplay the pane index number in all panes. As long as the pane index numbers are on the screen you can switch to an other pane by typing its number
tmux display-panesqShow pane numbers in the tmux window's panesAdd -t sessionname if there are multiple sessions of tmux running (not tested by us)
oSwap two panes
{Rotates the current pane through the panes clockwise and changes place with the other pane
}Rotates the current pane through the panes anti clockwise and changes place with the other pane
tmux set-option history-limit 5000 \; new-window Set the scroll back buffer to 5000 lines. Then open a new window. Adding -g in front of history-limit makes it globalAlways first set the scroll back buffer size before opening a new session, window or pane. The history-limit can also be set in .tmux.conf: set-option -g history-limit 30000. Warning: Setting a high value can consume a lot of RAM
spaceToggle between layouts with the number of already open panesWarning: This destroys your current layout
kill-panexKills the active paneAsks for confirmation
C-b : kill-pane -a -t 1 Kills all panes except for pane 1
show-messages~Show the error messages which occur briefly at the status line after issuing a command
display-time 5000 Display the messages for 5 seconds on the status line. The time is in millisecondsTime 0: display until a key is pressed
clock-mode -t 0tShow a clockOn pane 0

tmux.conf

/etc/tmux.conf is the global configuration file. We had trouble with this file resulting in errors. Putting the same content in $HOME/.tmux.conf worked fine
$HOME/.tmux.conf is the user's configuration file
When the .conf files is changed the changes will probably get activated after the tmux server is restarted
The active options can be shown

  • Global: tmux show-options -gw
  • User only: tmux show-options -w

Some handy settings

-g means global

set -g default-terminal "screen-256color"
set-option -g history-limit 50000
set-option display-time 5000
set-option display-panes-time 5000

Key bindings

Change CTRL-b to CTRL-a

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Change CTRL-b to ALT-b (ALT is called Meta)

unbind C-b
set -g prefix m-'\'
bind m-'\'-b send-prefix (or is it: bind m-b ?)


Configuration settings can also be set in a script so tmux starts with all desired settings

attach detach

C-b stands for CTRL-b

  1. Start tmux
  2. Login to a remote computer with ssh
  3. Start tmux on the remote computer (in the tmux instance you started at point 1)
  4. Start a program for instance cmus (ncurses music player)
  5. Goto an other computer and start a terminal
  6. Start tmux
  7. Login to the same remote computer with ssh
  8. Do tmux attach
  9. Now you can also control cmus from this computer on the remote computer. The interface size is determined by the computer with the smallest screen
  10. You can do the same on a third computer (steps 5 -9)
  11. If you want to close the program make sure there are no more computers using it, then just close it. Otherwise execute the next point (12)
  12. If you want to free up the terminal window, want to shutdown the computer you are working on, but do not want to close the program do: C-b C-b d (detach). To reinitiate it do from the steps 5 - 9 the needed steps
  13. Later you can login again with ssh to the remote computer and do tmux attach to continue were you left off

Default key bindings

Sorted by Explanation

CommandKeybindingExplanationRemark
Up, Down, Left, RightChange to the pane above, below, to the left, or to the right of the current pane
M-1 to M-5Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled
SpaceArrange the current window in the next preset layout
!Break the current pane out of the window
qBriefly display pane indexes
nChange to the next window
pChange to the previous window
DChoose a client to detach
wChoose the current window interactively
=Choose which buffer to paste interactively from a list
MClear the marked pane
cCreate a new window
-Delete the most recently copied buffer of text
dDetach the current client
iDisplay some information about the current window
Page UpEnter copy mode and scroll one page up
[Enter copy mode to copy text or view the history
:Enter the tmux command prompt
rForce redraw of the attached client
xKill the current pane
&Kill the current window
?List all key bindings
#List all paste buffers
mMark the current pane (see select-pane -m)
M-nMove to the next window with a bell or activity marker
M-pMove to the previous window with a bell or activity marker
;Move to the previously active pane
lMove to the previously selected windowLower case letter l (el)
]Paste the most recently copied buffer of text
'Prompt for a window index to select
.Prompt for an index to move the current window
fPrompt to search for text in open windows
rename-session -tcurrnenname newname$Rename the current session
rename-window [-t target-window] new-name,Rename the current window
M-Up, M-Down, M-Left, M-RightResize the current pane in steps of five cells
C-Up, C-Down, C-Left, C-RightResize the current pane in steps of one cell
M-oRotate the panes in the current window backwards
C-oRotate the panes in the current window forwards
sShow all windows in one window. Back to the active window with q or ENTER to go to the choosen window / pane
oSelect the next pane in the current window
0 to 9Select windows 0 to 9
C-bSend the prefix key (C-b) through to the application
~Show previous messages from tmux, if any
tShow the time
%Split the current pane into two, left and right
Split the current pane into two, top and bottom
C-zSuspend the tmux client
}Swap the current pane with the next pane
{Swap the current pane with the previous pane
LSwitch the attached client back to the last session
)Switch the attached client to the next session
(Switch the attached client to the previous session
zToggle zoom state of the current pane

Sorted by key

CommandKeybindingExplanationRemark
-Delete the most recently copied buffer of text
rename-window [-t target-window] new-name,Rename the current window
;Move to the previously active pane
:Enter the tmux command prompt
!Break the current pane out of the window
?List all key bindings
.Prompt for an index to move the current window
'Prompt for a window index to select
Split the current pane into two, top and bottom
(Switch the attached client to the previous session
)Switch the attached client to the next session
[Enter copy mode to copy text or view the history
]Paste the most recently copied buffer of text
{Swap the current pane with the previous pane
}Swap the current pane with the next pane
&Kill the current window
#List all paste buffers
%Split the current pane into two, left and right
=Choose which buffer to paste interactively from a list
~Show previous messages from tmux, if any
$Rename the current session
0 to 9Select windows 0 to 9
cCreate a new window
C-bSend the prefix key (C-b) through to the application
C-oRotate the panes in the current window forwards
C-Up, C-Down, C-Left, C-RightResize the current pane in steps of one cell
C-zSuspend the tmux client
DChoose a client to detach
dDetach the current client
fPrompt to search for text in open windows
iDisplay some information about the current window
lMove to the previously selected window
LSwitch the attached client back to the last session
MClear the marked pane
mMark the current pane (see select-pane -m)
M-1 to M-5Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled
M-nMove to the next window with a bell or activity marker
M-oRotate the panes in the current window backwards
M-pMove to the previous window with a bell or activity marker
M-Up, M-Down, M-Left, M-RightResize the current pane in steps of five cells
nChange to the next window
oSelect the next pane in the current window
pChange to the previous window
Page UpEnter copy mode and scroll one page up
qBriefly display pane indexes
rForce redraw of the attached client
sShow all windows in one window. Back to the active window with q
SpaceArrange the current window in the next preset layout
tShow the time
Up, Down, Left, RightChange to the pane above, below, to the left, or to the right of the current pane
wChoose the current window interactively
xKill the current pane
zToggle zoom state of the current pane

Configuration from file

Run the following script to start a tmux session with one windows which has 3 panes

#!/bin/sh
#
# Setup a workspace called Workspace with one window
# The window has 3 panes. 
# The first pane, 0, set at 70%, split horizontally
# pane 0 is again split at 25%, split vertically
#
 
session="Workspace1"
 
cd ~
 
# set up tmux
tmux start-server
 
# create a new tmux session
tmux new-session -d -s $session -n Session1
 
# Split pane 0 horizontal by 70%
tmux splitw -v -p 70
 
# Select pane 0 
tmux selectp -t 0
 
# Split pane 0 vertiacally by 25%
tmux splitw -h -p 25
 
# Finished setup, attach to the tmux session!
tmux attach-session -t $session

In a chroot environment

In the chroot environment

mkdir -p usr/bin
cp /usr/bin/tmux usr/bin
vi .profile
  # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
      PATH="$HOME/bin:$HOME/usr/bin:$PATH"
    fi
source .profile
cp /usr/lib/x86_64-linux-gnu/{libutil.so.1,libutempter.so.0,libevent-2.1.so.6,libresolv.so.2 usr/lib/x86_64-linux-gnu,libpthread.so.0} usr/lib/x86_64-linux-gnu/  

Errors

$ tmux
tmux: invalid LC_ALL, LC_CTYPE or LANG

What did not solve the issue

  • Add export LANG=en_US.UTF-8 to .bashrc
  • Add export LANG=en_US.UTF-8 to .profile
  • Add locale.conf to etc/
  • cp -v /usr/sbin/update-locale usr/sbin/; usr/sbin/update-locale

However

  1. bash-5.0$ locale -a

locale: Cannot set LC_CTYPE to default locale: No such file or directory

locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
POSIX
-bash-5.0$ export LC_ALL="en_US.UTF-8"
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash-5.0$ su
-bash: su: command not found
-bash-5.0$ echo $LC_CTYPE
en_US.UTF-8
-bash-5.0$ echo $LC_MESSAGES
en_US.UTF-8
-bash-5.0$ echo $LC_COLLATE
en_US.UTF-8
  1. bash-5.0$ localectl set-locale LANG=en_US.UTF-8

localectl: error while loading shared libraries: libsystemd-shared-241.so: cannot open shared object file: No such file or directory

  1. bash-5.0$ localectl set-locale LANG=en_US.UTF-8

localectl needs:

  • libsystemd-shared-241.so
  • librt.so.1
  • librt.so.1
  • librt.so.1
  • librt.so.1
  • libcap.so.2
  • libcap.so.2
  • libcap.so.2
  • libcap.so.2
  • libacl.so.1
  • libcryptsetup.so.12
  • libgcrypt.so.20
  • libip4tc.so.0
  • libkmod.so.2
  • libmount.so.1

And more

tmux on Arch Linux
tmux_2.4_copy_mode_vim.md configuration file on Github
tmux cheatsheet
An other cheatsheet

Restore session

Restore tmux session after reboot
10 killer tmux tips
tmuxp and its dependency python3-tmuxp


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
tmux.txt · Last modified: 23-05-2023 00:02 by wim