tmux Command in Linux: Sessions, Windows, and Panes

By 

Updated on

8 min read

Using tmux to manage terminal sessions, windows, and panes in Linux

When you run a long task over SSH and the connection drops, everything running in that terminal dies with it. Tmux keeps your sessions alive on the server, so you can disconnect, reconnect later, and continue exactly where you left off.

Tmux is a terminal multiplexer, an alternative to GNU Screen . It allows you to start a session and open multiple windows inside it. Each window occupies the entire screen and can be split into rectangular panes. You can easily switch between multiple programs in one terminal, detach them, and reattach them to a different terminal.

All commands in Tmux start with a prefix, which by default is Ctrl+b.

This guide covers the installation and usage of Tmux to get you up and running.

Quick Reference

For a printable quick reference, see the Tmux cheatsheet .

ActionKey / Command
New sessiontmux new -s name
New session (detached)tmux new -s name -d
List sessionstmux ls
Attach to sessiontmux attach-session -t name
Switch sessionCtrl+b s
DetachCtrl+b d
New windowCtrl+b c
Next windowCtrl+b n
Split verticallyCtrl+b %
Split horizontallyCtrl+b "
Navigate panesCtrl+b Arrow keys
Cycle pane layoutsCtrl+b Space
Zoom paneCtrl+b z
Close paneCtrl+b x
Copy modeCtrl+b [
PasteCtrl+b ]
Kill sessiontmux kill-session -t name
Reload configtmux source-file ~/.tmux.conf

Syntax

The basic tmux command syntax is:

txt
tmux [OPTIONS] [COMMAND [FLAGS]]

Run tmux without a command to start a new session. Use subcommands such as new, attach, ls, or kill-session when you want to manage sessions from the shell.

A few options are useful when starting tmux from the shell:

  • -V - Print the tmux version and exit
  • -2 - Force tmux to assume the terminal supports 256 colors
  • -u - Force UTF-8 mode
  • -f - Use an alternative configuration file instead of ~/.tmux.conf
  • -CC - Start tmux in control mode, which terminals such as iTerm2 on macOS use to integrate tmux sessions with native tabs and splits

Installing Tmux

You can install Tmux using the package manager of your distribution.

Ubuntu and Debian

Terminal
sudo apt install tmux

Fedora, RHEL, and Derivatives

Terminal
sudo dnf install tmux

macOS

Terminal
brew install tmux

Creating a New Tmux Session

To start a new session, run tmux in your terminal:

Terminal
tmux

This opens a new session, creates a window inside it, and starts a shell. You will see a status line at the bottom of the screen showing the session name and window list.

Tmux session with the status line showing the session name and window list at the bottom of the terminal

By default, sessions are named with a number starting from 0. To create a session with a descriptive name, use the -s flag:

Terminal
tmux new -s work

Named sessions are easier to manage when you have several running at the same time. You can also start a session in the background without attaching to it by adding the -d flag:

Terminal
tmux new -s backup -d

This is useful when you want to launch a long-running process inside tmux from a script or another session.

To see all available key bindings at any time, press Ctrl+b ?.

Detaching from a Session

You can detach from the Tmux session and return to your normal shell by typing:

Ctrl+b d

The programs running in the Tmux session will continue to run after you detach.

Reattaching to a Session

To attach to a session, you first need to find its name. To get a list of currently running sessions, type:

Terminal
tmux ls

The name of the session is the first column of the output:

output
0: 1 windows (created Thu Jan 30 09:38:43 2026) [158x35]
my_session: 1 windows (created Thu Jan 30 10:13:11 2026) [78x35]

There are two running sessions. The first one is named 0 and the second one my_session.

To attach to session 0, type:

Terminal
tmux attach-session -t 0

To attach to the most recently used session, you can simply run:

Terminal
tmux attach

Switching Between Sessions

When you have multiple sessions running, you can switch between them without detaching first.

Press Ctrl+b s to open an interactive session list. Use the arrow keys to pick a session and press Enter to switch to it.

You can also switch from the command line inside tmux by pressing Ctrl+b : and typing:

Terminal
switch-client -t work

To cycle through sessions quickly:

  • Ctrl+b ( - Switch to the previous session
  • Ctrl+b ) - Switch to the next session

Working with Windows

When you start a new Tmux session, it creates a single window with a shell in it.

To create a new window, type Ctrl+b c. Windows are numbered starting from 0. A list of all windows is shown on the status line at the bottom of the screen.

The following key bindings are used for managing windows:

  • Ctrl+b c - Create a new window
  • Ctrl+b w - Choose a window from a list
  • Ctrl+b 0 - Switch to window 0 (by number)
  • Ctrl+b n - Switch to the next window
  • Ctrl+b p - Switch to the previous window
  • Ctrl+b , - Rename the current window
  • Ctrl+b & - Close the current window

Working with Panes

Tmux allows you to split a window into multiple panes. Each pane runs its own shell.

The following key bindings are used for managing panes:

  • Ctrl+b % - Split the current pane vertically (left and right)
  • Ctrl+b " - Split the current pane horizontally (top and bottom)
  • Ctrl+b o - Go to the next pane
  • Ctrl+b ; - Toggle between the current and previous pane
  • Ctrl+b Arrow keys - Move to the pane in the given direction
  • Ctrl+b Ctrl+Arrow keys - Resize the current pane
  • Ctrl+b Space - Cycle through pane layouts
  • Ctrl+b z - Toggle pane zoom (fullscreen)
  • Ctrl+b x - Close the current pane

Copy Mode

Tmux has a copy mode that allows you to scroll through the terminal output and copy text. To enter copy mode, type:

Ctrl+b [

You can then use the arrow keys or Page Up / Page Down to scroll. Press q to exit copy mode.

The selection keys depend on the copy-mode key table. Tmux uses Emacs-style keys by default unless you enable vi mode with set -g mode-keys vi.

With the default Emacs-style keys:

  1. Press Ctrl+Space to start selecting text.
  2. Move the cursor to highlight the text you want to copy.
  3. Press Alt+w to copy the selected text and exit copy mode.
  4. Press Ctrl+b ] to paste the copied text.

With vi-style keys:

  1. Press Space to start selecting text.
  2. Move the cursor to highlight the text you want to copy.
  3. Press Enter to copy the selected text.
  4. Press Ctrl+b ] to paste the copied text.

Killing Sessions

To kill a specific Tmux session, use:

Terminal
tmux kill-session -t session_name

To kill all sessions except the current one:

Terminal
tmux kill-session -a

To kill the Tmux server and all sessions:

Terminal
tmux kill-server

Customizing Tmux

When Tmux is started, it reads its configuration from ~/.tmux.conf if the file is present.

Here is a sample ~/.tmux.conf configuration with a few useful options:

~/.tmux.conftmux
# Improve colors
set -g default-terminal 'tmux-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Enable mouse support
set -g mouse on

# Customize the status line
set -g status-style 'fg=green,bg=black'

To reload the configuration without restarting Tmux:

Terminal
tmux source-file ~/.tmux.conf

Or from within Tmux, type Ctrl+b : and enter:

Terminal
source-file ~/.tmux.conf

Troubleshooting

sessions should be nested with care, unset $TMUX to force
You tried to start a new session from inside an existing one. Detach from the current session with Ctrl+b d first, or use switch-client to move between sessions instead of nesting them.

no server running on /tmp/tmux-1000/default
There are no active sessions, so there is nothing to attach to. The tmux server starts with the first session and exits when the last one is killed. Create a new session with tmux new -s name.

Sessions are gone after a reboot
Tmux sessions live in memory and do not survive a restart of the machine. If you need your layout and programs back after a reboot, use a plugin such as tmux-resurrect to save and restore sessions.

Colors look wrong inside tmux
The terminal type advertised by tmux does not match what your terminal supports. Add set -g default-terminal 'tmux-256color' to your ~/.tmux.conf, or start tmux with the -2 flag to force 256-color mode.

FAQ

What is the difference between Tmux and GNU Screen?
Both are terminal multiplexers, but Tmux has a more modern codebase, better pane management, a scriptable command interface, and more active development. Screen is still widely available but receives fewer updates.

How do I scroll in Tmux?
Press Ctrl+b [ to enter copy mode, then use the arrow keys or Page Up / Page Down to scroll. Press q to exit copy mode. Alternatively, enable mouse support with set -g mouse on in your ~/.tmux.conf to scroll with the mouse wheel.

How do I change the prefix key?
Add the following to your ~/.tmux.conf to change the prefix from Ctrl+b to Ctrl+a: set -g prefix C-a and unbind C-b.

Can I use the mouse in Tmux?
Yes. Add set -g mouse on to your ~/.tmux.conf. This enables mouse-based pane selection, window switching, pane resizing, and scrolling.

How do I rename a session?
From within Tmux, press Ctrl+b $ and type the new name. From the command line, use tmux rename-session -t old_name new_name.

Conclusion

The tmux command gives you persistent sessions that survive disconnects, split panes for side-by-side work, and named windows to keep projects organized. For the full option list, run man tmux or see the tmux User’s Manual .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page