Catalog / Terminal Multiplexers Cheatsheet (tmux & screen)

Terminal Multiplexers Cheatsheet (tmux & screen)

A comprehensive cheat sheet covering essential commands and configurations for using tmux and screen, two popular terminal multiplexers. This guide provides a quick reference for managing sessions, windows, and panes, enhancing productivity in the terminal.

tmux Basics

Session Management

tmux new -s <session-name>

Create a new tmux session with a specified name.

tmux attach -t <session-name>

Attach to an existing tmux session.

tmux ls

List all active tmux sessions.

tmux kill-session -t <session-name>

Kill a specific tmux session.

tmux rename-session -t <old-name> <new-name>

Rename a tmux session.

tmux detach or Ctrl+b d

Detach from the current tmux session.

Window Management

Ctrl+b c

Create a new window.

Ctrl+b ,

Rename the current window.

Ctrl+b n

Go to the next window.

Ctrl+b p

Go to the previous window.

Ctrl+b <window-number>

Go to a specific window by number.

Ctrl+b w

List all windows and choose one to switch to.

Ctrl+b &

Kill the current window.

Pane Management

Ctrl+b %

Split the current window into two panes vertically.

Ctrl+b "

Split the current window into two panes horizontally.

Ctrl+b <arrow-key>

Move to the pane in the direction of the arrow key.

Ctrl+b o

Cycle through the panes.

Ctrl+b z

Toggle pane zoom (maximize/restore).

Ctrl+b !

Break the current pane out into a new window.

Ctrl+b x

Kill the current pane.

screen Basics

Session Management (screen)

screen

Start a new screen session.

screen -S <session-name>

Start a new named screen session.

screen -r

Resume a detached screen session.

screen -r <session-name>

Resume a specific named screen session.

screen -ls

List all active screen sessions.

Ctrl+a d

Detach from the current screen session.

kill <screen-pid>

Kill a screen session by its PID (found with screen -ls).

Window Management (screen)

Ctrl+a c

Create a new window.

Ctrl+a n

Go to the next window.

Ctrl+a p

Go to the previous window.

Ctrl+a <number>

Switch to window number <number>.

Ctrl+a "

Display a list of windows for selection.

Ctrl+a A

Rename the current window.

Ctrl+a k

Kill the current window.

Other Useful Commands (screen)

Ctrl+a ?

Display help.

Ctrl+a a

Send Ctrl+a to the application running in the window.

Ctrl+a t

Display the time and load average.

Ctrl+a v

View screen version information.

Ctrl+a H

Enable/disable logging of the current window to a file.

Configuration (tmux)

tmux Configuration File

The tmux configuration file is typically located at ~/.tmux.conf. This file allows you to customize tmux behavior and keybindings.

Example:

# Set prefix key to Ctrl+a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# Reload configuration file
bind r source-file ~/.tmux.conf

# Enable mouse support
set-option -g mouse on

# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

Keybindings

bind-key <key> <command>

Bind a key to a specific tmux command.

Example:
bind-key k kill-pane (Kill pane with ‘k’)

unbind <key>

Unbind a key.

Example:
unbind % (Unbind the default split-vertical command)

Options

set-option -g <option> <value>

Set a global tmux option.

Example:
set-option -g status-bg black (Set status bar background to black)

set-window-option -g <option> <value>

Set a window-specific tmux option.

Example:
set-window-option -g automatic-rename on (Automatically rename windows)

Configuration (screen)

screen Configuration File

The screen configuration file is typically located at ~/.screenrc. This file allows you to customize screen behavior and keybindings.

**Example:

# Set the default window title
defaulttitle "Screen Session"

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %H ][ %A, %d %m %Y ][ %l ]%{= kw}%?%-w%?%{r}(%{W})%{w}%?%+w%?'

# Set a different escape key (Ctrl+z)
escape ^Zz

Keybindings (screen)

bindkey <key> <command>

Bind a key to a specific screen command.

Example:
bindkey ^k kill (Kill window with Ctrl+a followed by Ctrl+k)

unbind <key>

Unbind a key.

Example:
unbind k (Unbind the default kill command from Ctrl+a k)

Options (screen)

defscrollback <lines>

Set the default scrollback buffer size.

Example:
defscrollback 10000 (Set scrollback to 10000 lines)

vbell on/off

Enable or disable visual bell.

Example:
vbell on (Enable visual bell)