tmux vs screen on FreeBSD: Step-by-Step Guide
In this article
Terminal multiplexing lets you run several shell sessions inside one terminal window, detach from them, and reattach later—even after an SSH connection drops. On FreeBSD you can use either tmux or screen; both are in the ports tree and packages. The shortest path is to install one with pkg install tmux (or pkg install screen), start it, and learn a handful of prefix-key commands. This guide walks through both tools step by step, with the exact commands and key sequences, plus the mistakes that trip people up on FreeBSD.
What You'll Need
- A FreeBSD system with a working shell (sh, csh, or bash) and a terminal or SSH client.
- Root or sudo access to install packages, or an existing tmux/screen binary if already installed.
- Basic familiarity with the command line and how to exit a text editor (you may want to edit a config file later).
Step-by-Step
- Check whether tmux or screen is already installed. Run
tmux -Vandscreen -v. If either prints a version, skip the install step for that tool. - Install the package you want. As root, run
pkg install tmuxorpkg install screen. If you prefer ports,cd /usr/ports/sysutils/tmux && make install clean(orsysutils/screen). Package names and paths are stable on FreeBSD, but the exact version number printed by-Vwill differ by release. - Start tmux. Type
tmuxand press Enter. You get a new shell inside a tmux session with a status bar at the bottom. The default prefix key isCtrl+b: press and release it, then press the next key. - Create and switch windows in tmux. Press
Ctrl+bthencto create a new window. PressCtrl+bthennfor the next window,pfor the previous, and0–9to jump to a numbered window. The status bar lists windows and highlights the active one. - Split panes in tmux. Press
Ctrl+bthen%for a vertical split, or"for a horizontal split. Move between panes withCtrl+bthen an arrow key. Close a pane by typingexitin it. - Detach and reattach in tmux. Press
Ctrl+bthendto detach; the session keeps running in the background. To list sessions, runtmux ls. To reattach, runtmux attach(ortmux attach -t 0for a specific session). - Start screen. Type
screenand press Enter. The default prefix isCtrl+a. - Create and switch windows in screen. Press
Ctrl+athencfor a new window. PressCtrl+athennorpto cycle, andCtrl+athen0–9to jump to a number. The window list appears briefly at the bottom. - Split regions in screen. Screen's splitting is more limited than tmux. Press
Ctrl+athenSfor a horizontal split, andCtrl+athenTabto move between regions. UseCtrl+athenQto close other regions. - Detach and reattach in screen. Press
Ctrl+athendto detach. Runscreen -lsto list sessions, andscreen -rto reattach (add the PID or session name if more than one exists). - Make the choice persistent. For tmux, create
~/.tmux.confand add lines such asset -g mouse onto enable mouse selection. For screen, create~/.screenrc. Reload tmux config withtmux source-file ~/.tmux.conf; screen reads its config at startup. - Use it over SSH. Start tmux or screen after logging in over SSH, run long jobs, then detach before disconnecting. Reconnect later and reattach—the job keeps running as long as the FreeBSD host stays up and the session is not killed.
Common Mistakes
- Pressing the prefix and the command key together. The prefix is a two-step sequence: release
Ctrl+b(tmux) orCtrl+a(screen), then press the next key separately. - Confusing detach with exit. Typing
exitin the last pane or window ends the session. Detaching with the prefix plusdleaves it running. - Forgetting which tool owns the prefix. Screen uses
Ctrl+a, which is also the shell's beginning-of-line key. If you pressCtrl+atwice in screen, it sends a literalCtrl+ato the shell. - Assuming sessions survive a reboot. Neither tmux nor screen preserves sessions across a FreeBSD reboot; they survive disconnects, not power loss.
- Editing config in the wrong file. tmux reads
~/.tmux.conf; screen reads~/.screenrc. Putting tmux options in.screenrcdoes nothing.
Tips
- Name sessions for clarity:
tmux new -s workandscreen -S work. Reattach withtmux attach -t workorscreen -r work. - Use
tmux lsandscreen -lsto see what is running before starting a duplicate session. - Enable mouse mode in tmux with
set -g mouse onin~/.tmux.confif you want clickable pane selection and scrollback. - Scrollback: in tmux press
Ctrl+bthen[to enter copy mode and use arrow keys or Page Up; pressqto exit. In screen pressCtrl+athen[andqto leave. - On FreeBSD, install from packages for speed; use ports only if you need custom build options.
Troubleshooting
- "tmux: not found" or "screen: not found". The package is not installed or not in your PATH. Run
pkg install tmuxorpkg install screenas root, then checkwhich tmux. - Cannot reattach: "no sessions" or "session already attached". List sessions with
tmux lsorscreen -ls. If a screen session is marked Attached but your old connection is gone, usescreen -d -rto detach it elsewhere and reattach here. - Prefix key does nothing. Confirm you are inside tmux or screen (the status bar or window list should be visible). If you are in a nested session, the inner tool may be capturing the prefix; detach the inner one first.
- Config changes ignored. For tmux, reload with
tmux source-file ~/.tmux.confor restart the server withtmux kill-server(this ends all tmux sessions—save work first). For screen, exit and restart screen; it reads~/.screenrconly at startup. - Session disappeared after logout. The session was likely exited, the host rebooted, or the process was killed. tmux and screen do not survive a reboot; restart the session and rerun the job.
Frequently Asked Questions
Is tmux or screen better on FreeBSD?
Both work well. tmux has more flexible pane splitting and a more active configuration ecosystem; screen is smaller and has been around longer. Choose based on the key bindings you prefer.
Can I run tmux and screen at the same time?
Yes. They are separate programs. You can even run screen inside a tmux pane, though nested prefixes can be confusing.
Do sessions survive an SSH disconnect?
Yes, if you detach before disconnecting or the connection drops while the session is running. The session lives on the FreeBSD host, not on your local machine.
How do I kill a stuck session?
For tmux, run tmux kill-session -t name. For screen, run screen -S name -X quit. This ends the session and any processes inside it.
Where are the config files?
tmux uses ~/.tmux.conf; screen uses ~/.screenrc. Create them in your home directory if they do not exist.
Does tmux work on a FreeBSD console without X?
Yes. tmux and screen are terminal programs and work in a plain text console as well as over SSH.