tmux
tmux keybinding
Change tmux keybinding prefix from Ctrl-B to Ctrl-A.
Open the tmux config file:
$ vim ~/.tmux.conf
and add the following
# command prefix
unbind C-b
set-option -g prefix C-a
Basic commands
# create new session
tmux
# create named session
tmux new -s <name>
# create detached session
tmux new -s <name> -d
# detach from session
<ctrl+a d>
# list sessions
tmux ls
# attach to session
tmux attach
# or
tmux a
# attach to named session
tmux a -t <name>
# kill named session
tmux kill-session -t <name>
# kill active session
<ctrl+a x y>
# kill tmux server (and all its sessions)
tmux kill-server
Advanced
.bashrc to open in tmux session by default
It might be useful to "auto start" tmux session, e.g. on remote server that you are SSHing into.
Add the following to your .bashrc on the remote machine:
if [ -z "$TMUX" ]; then
tmux attach -t default || tmux new -s default
fi
"Explanation"
-z stringis True if the string is null. Since$TMUXis null iff we are not in a tmux session, this is equivalent toif not in tmux sessiontmux attach -t defaultwill attempt to attach to a session nameddefault- if there is no such session it will fail, and
||means we pass to the second command tmux new -s defaultwill create a new tmux session nameddefault