Section 1 of 13

1 Before you start

Before you begin, take a few minutes to check what you already know and how confident you feel. You will see the same questions again at the end of the module — this helps both you and us measure what you have learned. Click an option for every question and confidence rating, then click Next to continue.

Pre-test

What is the main reason to run a long job inside tmux?

Pre-test

The default tmux prefix key is:

Pre-test

You are inside a session with a job running and want to leave it running and go home. What do you do?

Pre-test

Which command reattaches to a running session named cohort?

Pre-test

After the prefix, which keys split the current window into panes?

Pre-test

In the tmux hierarchy, which containment relationship is correct?

Pre-test

Which command starts a new tmux session named cohort so you can find it again later?

Pre-test

Your mouse wheel will not scroll and you need to read output that rolled off the top of a pane. What do you press?

Pre-confidence

I can start a named tmux session, detach from it, and reattach later.

Not at all confident
Fully confident
Pre-confidence

I can create windows and split panes inside a session.

Not at all confident
Fully confident
Pre-confidence

I understand why tmux is safer than nohup for a long or remote job.

Not at all confident
Fully confident
Section 2 of 13

2 Introduction

tmux stands for terminal multiplexer. Think of it as a tool that gives you two powerful abilities:

  • Persistence: your code keeps running in the background even if you close your laptop, lose Wi-Fi, or log out.
  • Organization: you can split one terminal window into multiple tabs and panes, so you can edit code, run it, and watch logs all at once
A tmux session lives on the remote server rather than on your laptop, so it keeps running after you disconnect and can be split into multiple panes
A tmux session lives on the remote server rather than on your laptop, so it keeps running after you disconnect and can be split into multiple panes

In this particular tutorial, there are two kinds of input:

  • Commands that you type at the prompt. For example tmux ls
  • Keyboard shortcuts that uses the Prefix. We will bold it. For example, Ctrl + b then c. You don’t “run” these; you press the keys.

To understand Tmux, imagine a tree-like hierarchy of your workspace:

Session: A dedicated workspace that runs in the background. Your work lives here. Even if you disconnect your terminal, the session stays alive.

Window: A full-screen tab inside a session. You can have several open at once.

Pane: A split-screen tile within a single window. Perfect for side-by-side multitasking.

In short: a session contains windows, and a window can be split into panes.

In tmux, a session holds multiple windows shown as numbered tabs in the status bar, and a prefix keypress (Ctrl + b) followed by one key lets you create, move between, jump to, rename, and list them.
In tmux, a session holds multiple windows shown as numbered tabs in the status bar, and a prefix keypress (Ctrl + b) followed by one key lets you create, move between, jump to, rename, and list them.
Section 3 of 13

3 Sessions That Outlive the Terminal

Normally your terminal window and the programs inside it are tied together. Close the window (or lose Wi-Fi) and everything crashes, taking your progress with it.

Tmux changes this by adding a layer in between:

  • It runs a continuous session in the background.
  • Your terminal window is just a viewport looking into that session.
  • You can detach the viewport at any time; the session keeps running, untouched.
  • Later you can attach again from any terminal, and your workspace is exactly as you left it.
A tmux session is a long-lived process running in the background; your terminal is only a viewport onto it, so detaching the window (or losing your connection) leaves the work running, and reattaching from any terminal returns you to exactly the state it has reached.
A tmux session is a long-lived process running in the background; your terminal is only a viewport onto it, so detaching the window (or losing your connection) leaves the work running, and reattaching from any terminal returns you to exactly the state it has reached.

Inside a session you organize work further with windows (like browser tabs) and panes (screen splits).

Section 4 of 13

4 Installing tmux

Note: Tmux cannot be run in the bash scratchpad. You can fire up a Terminal if you on macOS or UNIX-based system. If you are using Windows OS, you can launch via WSL.

The following tutorial assumes that you are running on the Terminal on your local computer

First, check whether you already have it

$ tmux -V

If that prints a version (e.g. tmux 3.4), you are set. If you get command not found, install it using the line from your system:

# Debian/Ubuntu/WSL
$ sudo apt update && sudo apt install -y tmux
# macOS (Homebrew)
$ brew install tmux
# Fedora/RHEL
$ sudo dnf install -y tmux
Section 5 of 13

5 The Prefix Key

To launch Tmux, type the following:

$ tmux

To avoid mixing up its own shortcuts with keystrokes meant for programs running inside it (Python, Vim, etc.), tmux uses a two-step handshake called the Prefix key.

The default prefix is: Ctrl + b

To run any tmux shortcut:

Press and hold Ctrl, then tap b.

Release both keys.

Tap the command key.

To know if you did the prefix key properly, try the following:

Press and hold Ctrl, then tap b.

Release both keys.

Press the lower case t

If you did it correctly, a large digital clock takes over the pane. Press q or Esc to dismiss it.

To leave tmux entirely, type exit in the shell. That closes the current pane (and the window, then the session, once it is the last pane).

A tmux shortcut is sent in two steps rather than one held chord: you press and release the prefix (Ctrl+b), then tap the command key, and that release-then-tap is exactly how tmux distinguishes its own shortcuts from keystrokes meant for the program running inside the pane.
A tmux shortcut is sent in two steps rather than one held chord: you press and release the prefix (Ctrl+b), then tap the command key, and that release-then-tap is exactly how tmux distinguishes its own shortcuts from keystrokes meant for the program running inside the pane.
Section 6 of 13

6 Starting, Detaching, Reattaching

This is a cleaner, more interactive alternative to old methods like running scripts with nohup: you can jump right back into a live session and see real-time output.

Step 1. Start and leave it running

Always name your sessions with the -s flag so you can find them later:

$ tmux new -s cohort

A green status bar appears at the bottom of the screen. You are now safely inside tmux.

Step 2. Detach and leave it running

Once a long-running pipeline or script is going, you can safely walk away by detaching:

Shortcut: Ctrl + b and then press d

tmux drops you back to your ordinary prompt. Your job is still running invisibly in the background.

Step 3. List and Reattach

Whether you closed your laptop, went to lunch, or logged out, your session is waiting.

  • List your active sessions
$ tmux ls
  • Reattach to your session
$ tmux attach -t cohort

Step 4. Kill the Session

When the pipeline is completely finished, close the session so it stops using resources. You can either type exit inside the Tmux terminal, or destroy it from the outside using:

$ tmux kill-session -t cohort
A tmux session runs on the server independently of your terminal, so you can detach and disconnect while the job keeps running, then reattach later to pick up exactly where you left off, and kill the session when the work is done.
A tmux session runs on the server independently of your terminal, so you can detach and disconnect while the job keeps running, then reattach later to pick up exactly where you left off, and kill the session when the work is done.
Section 7 of 13

7 Windows - Tabs Inside a Session

A window fills your entire terminal. Think of them like browser tabs: flip between full-screen tasks without opening new terminal applications.

A typical layout might include:

  • Window 1: Vim with your analysis script open.
  • Window 2: running the actual script.
  • Window 3: exploring the output data.
  • Here are some of the common window shortcuts
  • Remember that prefix means ctrl + b (by default)
  • prefix then c - Opens a brand new window
  • prefix then n or p - Flips to the next or previous window
  • prefix then 0-9 - Jumps straight to a specific numbered window
  • prefix then , - Renames the current window for easy organizing
  • prefix then w - Opens a list of windows so you can pick one
Section 8 of 13

8 Panes - Splitting One Window

Panes let you tile a single window so you can watch multiple processes at the same time. The default bindings feel cryptic at first, but they quickly become muscle memory.

A classic data-work split: Run your pipeline in the left pane, and keep a live log (tail -f run.log) going in the right pane to watch its progress. If you need to see one side clearly, you can zoom into it and then restore the split.

  • prefix then % - Splits the screen Left / Right
  • prefix then " - Splits the screen Top / Bottom
  • prefix then arrow keys - Moves your cursor between the active panes
  • prefix then z - Toggles the current pane to full screen (and back)
  • prefix then x - Closes the current pane (asks for confirmation)
tmux lets you split one terminal into a pipeline pane and a live-log pane, zoom either one to full screen to read it, then restore and move between panes, all without leaving your session.
tmux lets you split one terminal into a pipeline pane and a live-log pane, zoom either one to full screen to read it, then restore and move between panes, all without leaving your session.
Section 9 of 13

9 Scrolling Back

By default, your mouse wheel may not scroll inside a Tmux session. To read terminal output that has rolled off the top of your screen, you need to use Copy Mode:

Enter Copy Mode: Press prefix then [

Scroll: Use your arrow keys, Page Up, or standard Vim navigation keys (j, k, Ctrl-u, Ctrl-d).

Exit: Press q to leave copy mode and return to your prompt.

In tmux a pane keeps a scrollback history, and you reach it by entering Copy Mode with the prefix then [, navigating up with the arrows, PageUp, or k, and pressing q to return to the live prompt.
In tmux a pane keeps a scrollback history, and you reach it by entering Copy Mode with the prefix then [, navigating up with the arrows, PageUp, or k, and pressing q to return to the live prompt.
Section 10 of 13

10 A Little Configuration

Tmux reads a hidden file called ~/.tmux.conf when it starts. While you do not strictly need one, many developers find the default Ctrl-b prefix to be an awkward reach.

A common tweak is to remap the prefix to Ctrl-a and enable your mouse so you can click between panes and scroll naturally. You can add these rules to your config file:

set -g prefix C-a
bind C-a send-prefix
set -g mouse on
Section 11 of 13

11 The Payoff Workflow

Here is how you put all of these tools together for a long, heavy task (like a cohort run) directly on your laptop:

Start a Session: Run tmux new -s analysis to create a dedicated workspace.

Split the Screen: Press prefix then " to create a top and bottom pane.

Launch the Job: In the top pane, run your heavy script (e.g., ./cohort_summary.sh big_cohort.csv out.tsv).

Monitor the Job: Click or navigate to the bottom pane and run tail -f run.log to watch the live progress.

Detach and Walk Away: Press prefix then d. You can now shut your laptop lid, lose Wi-Fi, or go home. The job keeps running safely.

Return to Work: The next morning, open your terminal and run tmux attach -t analysis. Your job will be finished, and your exact split-screen layout will be waiting for you.

A tmux session lives on the machine rather than in your connection, so you can detach and disconnect (close the lid, lose Wi-Fi, go home) while your job keeps running, then reattach later to find it finished with your layout intact.
A tmux session lives on the machine rather than in your connection, so you can detach and disconnect (close the lid, lose Wi-Fi, go home) while your job keeps running, then reattach later to find it finished with your layout intact.
Section 12 of 13

12 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

What is the main reason to run a long job inside tmux?

Post-test

The default tmux prefix key is:

Post-test

You are inside a session with a job running and want to leave it running and go home. What do you do?

Post-test

Which command reattaches to a running session named cohort?

Post-test

After the prefix, which keys split the current window into panes?

Post-test

In the tmux hierarchy, which containment relationship is correct?

Post-test

Which command starts a new tmux session named cohort so you can find it again later?

Post-test

Your mouse wheel will not scroll and you need to read output that rolled off the top of a pane. What do you press?

Post-confidence

I can start a named tmux session, detach from it, and reattach later.

Not at all confident
Fully confident
Post-confidence

I can create windows and split panes inside a session.

Not at all confident
Fully confident
Post-confidence

I understand why tmux is safer than nohup for a long or remote job.

Not at all confident
Fully confident
Section 13 of 13

13 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)