In this chapter, we’ll explore tmux, a terminal multiplexer that allows you to manage multiple terminal sessions within a single window. By the end of this chapter, you’ll be able to create, manage, and customize tmux sessions, panes, and windows, making your workflow more efficient and organized.


Linux tmux on Debian 12 revolutionizes terminal multitasking, enabling efficient tmux session management for developers, admins, or remote workers. This chapter covers creating sessions, managing windows and panes, and customizing workflows with tmux, byobu, and plugins, empowering beginners to boost productivity.

Learning Objectives: By the end of this chapter, you’ll be able to manage multiple terminal sessions, persist work across disconnections, and customize tmux for streamlined tasks.

Why Learn Linux tmux?

tmux enhances productivity by supporting multitasking, persistent sessions, and remote work, ideal for managing development tasks or server administration.

Getting Started with tmux

tmux is a terminal multiplexer for multiple sessions.

$ sudo apt install tmux

Example:

$ tmux

Managing tmux Sessions

Example:

$ tmux new -s work

Working with Windows and Panes

Windows

Panes

Example: Split pane: Ctrl-b %

Customizing tmux

Edit ~/.tmux.conf:

$ nano ~/.tmux.conf
unbind C-b
set-option -g prefix C-a
bind C-a send-prefix
set -g mouse on

Reload:

$ tmux source-file ~/.tmux.conf

Plugins with tmux Plugin Manager (TPM)

tpm extends tmux functionality.

$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add to ~/.tmux.conf:

set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'

Install: Ctrl-b I

Example: Save sessions with tmux-resurrect.

Alternative Multiplexer: screen

screen is a lightweight multiplexer.

$ sudo apt install screen

Example:

$ screen

Enhanced Interface with byobu

byobu improves tmux/screen usability.

$ sudo apt install byobu
$ byobu

Example:

$ byobu

Automated Layouts with tmuxinator

tmuxinator preconfigures session layouts.

$ sudo apt install ruby
$ gem install tmuxinator
$ tmuxinator new project

Example:

$ tmuxinator start project

Practical Examples

Dev setup:

$ tmux new -s dev
Ctrl-b %  # Split pane
$ vim code.py  # One pane
$ python code.py  # Another pane

Remote work:

$ tmux new -s server
$ tail -f /var/log/syslog

Practice Time!

  1. Start a tmux session with two windows.
  2. Split a window into panes and run commands.
  3. Detach and reattach a session.
  4. Customize ~/.tmux.conf with mouse support.
  5. Install a tpm plugin.

Try This: Run tmux new -s test and share a screenshot on X with #LinuxCommandLine!

Summary

Linux tmux on Debian 12, with tools like byobu and tmuxinator, streamlines terminal multitasking. Mastering tmux session management enhances productivity for coding, monitoring, or remote work.

Glossary of Commands, Tools, and Shortcuts

Reference: Linux Manpages, Debian APT.

Command/Tool Description
tmux Terminal multiplexer
tmux new Starts a session
tmux attach Reattaches a session
tpm Manages tmux plugins
screen Lightweight multiplexer
byobu Enhanced tmux/screen interface
tmuxinator Automates session layouts

That’s it for Chapter 23 ! You’ve now learned how to use tmux to manage multiple terminal sessions, windows, and panes. With this knowledge, you can organize your workflow, automate tasks, and work more efficiently in the terminal.


Previous: Chapter 22 | Next: Part IV