TechBuzzPro

tmux vs screen on FreeBSD: Step-by-Step Guide

· 6 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Check whether tmux or screen is already installed. Run tmux -V and screen -v. If either prints a version, skip the install step for that tool.
  2. Install the package you want. As root, run pkg install tmux or pkg install screen. If you prefer ports, cd /usr/ports/sysutils/tmux && make install clean (or sysutils/screen). Package names and paths are stable on FreeBSD, but the exact version number printed by -V will differ by release.
  3. Start tmux. Type tmux and press Enter. You get a new shell inside a tmux session with a status bar at the bottom. The default prefix key is Ctrl+b: press and release it, then press the next key.
  4. Create and switch windows in tmux. Press Ctrl+b then c to create a new window. Press Ctrl+b then n for the next window, p for the previous, and 0–9 to jump to a numbered window. The status bar lists windows and highlights the active one.
  5. Split panes in tmux. Press Ctrl+b then % for a vertical split, or " for a horizontal split. Move between panes with Ctrl+b then an arrow key. Close a pane by typing exit in it.
  6. Detach and reattach in tmux. Press Ctrl+b then d to detach; the session keeps running in the background. To list sessions, run tmux ls. To reattach, run tmux attach (or tmux attach -t 0 for a specific session).
  7. Start screen. Type screen and press Enter. The default prefix is Ctrl+a.
  8. Create and switch windows in screen. Press Ctrl+a then c for a new window. Press Ctrl+a then n or p to cycle, and Ctrl+a then 0–9 to jump to a number. The window list appears briefly at the bottom.
  9. Split regions in screen. Screen's splitting is more limited than tmux. Press Ctrl+a then S for a horizontal split, and Ctrl+a then Tab to move between regions. Use Ctrl+a then Q to close other regions.
  10. Detach and reattach in screen. Press Ctrl+a then d to detach. Run screen -ls to list sessions, and screen -r to reattach (add the PID or session name if more than one exists).
  11. Make the choice persistent. For tmux, create ~/.tmux.conf and add lines such as set -g mouse on to enable mouse selection. For screen, create ~/.screenrc. Reload tmux config with tmux source-file ~/.tmux.conf; screen reads its config at startup.
  12. 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) or Ctrl+a (screen), then press the next key separately.
  • Confusing detach with exit. Typing exit in the last pane or window ends the session. Detaching with the prefix plus d leaves it running.
  • Forgetting which tool owns the prefix. Screen uses Ctrl+a, which is also the shell's beginning-of-line key. If you press Ctrl+a twice in screen, it sends a literal Ctrl+a to 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 .screenrc does nothing.

Tips

  • Name sessions for clarity: tmux new -s work and screen -S work. Reattach with tmux attach -t work or screen -r work.
  • Use tmux ls and screen -ls to see what is running before starting a duplicate session.
  • Enable mouse mode in tmux with set -g mouse on in ~/.tmux.conf if you want clickable pane selection and scrollback.
  • Scrollback: in tmux press Ctrl+b then [ to enter copy mode and use arrow keys or Page Up; press q to exit. In screen press Ctrl+a then [ and q to 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 tmux or pkg install screen as root, then check which tmux.
  • Cannot reattach: "no sessions" or "session already attached". List sessions with tmux ls or screen -ls. If a screen session is marked Attached but your old connection is gone, use screen -d -r to 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.conf or restart the server with tmux kill-server (this ends all tmux sessions—save work first). For screen, exit and restart screen; it reads ~/.screenrc only 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.