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
- Start session:
$ tmux
- Detach:
Ctrl-b d - Reattach:
$ tmux attach
Example:
$ tmux
Managing tmux Sessions
- Named session:
$ tmux new -s dev
- List sessions:
$ tmux ls
- Switch:
$ tmux switch -t dev
- Kill:
$ tmux kill-session -t dev
Example:
$ tmux new -s work
Working with Windows and Panes
Windows
- New window:
Ctrl-b c - Rename:
Ctrl-b , - Next:
Ctrl-b n - Previous:
Ctrl-b p
Panes
- Horizontal split:
Ctrl-b " - Vertical split:
Ctrl-b % - Switch:
Ctrl-b o - Resize:
Ctrl-b Alt-arrow
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
- Start:
$ screen
- Detach:
Ctrl-a d - Reattach:
$ screen -r
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!
- Start a
tmuxsession with two windows. - Split a window into panes and run commands.
- Detach and reattach a session.
- Customize
~/.tmux.confwith mouse support. - Install a
tpmplugin.
Try This: Run
tmux new -s testand 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