Getting Started with tmux / Chapter 1 — Getting Started with tmux (lessons 1–4) / Lesson 1
What tmux Is: A Server That Keeps Running Behind Your Terminal
Time needed: about 7 min (estimate)
Reading settings
These settings are remembered on this device only.
You can try the opening of this lesson without an account.
Three problems tmux solves
tmux is a terminal multiplexer: a tool that creates many terminals inside one terminal and manages them together. It solves three problems. First, whatever you were running stops when you close the terminal or your SSH connection drops. Second, you want to see your editor, server, and logs at once, but you have only one screen. Third, you rebuild the same arrangement by hand every morning.
Tabs and splits in a terminal app solve the second problem, but not the first or the third. tmux works with the same keys on your own machine and on a server, so what you learn once carries over to any machine you SSH into. In this course we build up a workspace step by step, using work on a small website (the folder ~/site) as our subject.
Sessions, windows, and panes
Inside tmux there are three layers. A session is one piece of work, a window is one full screen inside it, and a pane is one region of a split window. Shells and programs run inside panes. The diagram below shows, ahead of time, the shape we'll build later in this course.
The three layers
Reading the first screen
Type just tmux in a terminal, and a new session is created and you're put inside it. Almost nothing looks different: one status line appears at the bottom. Below is a real capture from a terminal 64 columns wide and 14 rows tall.
Screen
Reading the status line from the left: [0] is the session name (a number starting from 0 if you don't name it), and 0:tmux* means "window 0, named tmux, and * marks the window you're looking at". On the right are the pane title (the host name unless you change it) and the time and date. The window name follows the command running inside, so after a moment it becomes 0:bash* or 0:zsh*.
The server and the client
The first tmux starts one server process in the background. That server owns every session, window, and pane. The terminal you are looking at is a client: it connects to the server through a socket file and merely displays the screen. You can check this from another terminal:
Terminal
Now let's simply close the terminal window that's showing tmux. Before closing it, we typed echo still-here-1 in the pane. Seen from another terminal, there are now zero clients, but the session is still there and so is the content of the pane. Only the (attached) mark is gone.
Terminal
Rebuilding the listing as a tree
You can list what the server holds with list-sessions, list-windows, and list-panes. -a means "from every session", and -F lets you choose what to print (Lesson 14). Below, we actually built the shape in the diagram above, captured its pane list, and rebuild it into a three-layer tree with Python. A location is written as session:window.pane.
Tab indents. To leave the editor, press Esc, then Tab.
Create a free account to keep reading
With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.
Report a problem with this lesson
Log in to send a report.