tmux commands and shortcuts cheat sheet
Installation and startup
-
sudo apt install tmuxDebian and Ubuntu: installs tmux.
-
sudo dnf install tmuxAlmaLinux, Rocky Linux, and RHEL: installs tmux.
-
tmux -VShows the tmux version installed on the server.
-
tmuxOpens a new unnamed session, and tmux gives it a number. For everyday work, it's better to name the session so it's easy to get back to.
Sessions: open, detach, and reattach
-
tmux new -s workOpens a new session named work. The full form of the command is tmux new-session.
-
tmux new -A -s workAttaches to the work session if it already exists, and creates it if it doesn't. Handy to run every time, right after you log in to the server.
-
tmux new -d -s job './long-task.sh'Opens a session in the background, without attaching to it, and runs the quoted command in it. While the command runs, you can attach to the session to see the output, and when the command finishes, the session closes.
-
Ctrl+b dDetaches the terminal from the session. The session and all its processes keep running on the server, even after the SSH connection is closed.
-
tmux lsLists the active sessions on the server, with the number of windows in each session and whether a terminal is attached to it. The full form is tmux list-sessions.
-
tmux attach -t workReattaches to the work session, for example after your SSH connection dropped. The full form is tmux attach-session.
-
tmux attachAttaches to a session without naming it. Useful when only one session is running on the server.
-
tmux attach -d -t workAttaches to the work session and detaches any other terminals attached to it, for example an old connection from another computer.
-
Ctrl+b sShows the list of sessions and lets you switch to another session with the arrow keys and Enter.
-
Ctrl+b ( / Ctrl+b )Switch to the previous and the next session, respectively.
-
Ctrl+b $Renames the current session.
-
tmux rename-session -t work mainRenames the work session to main, from outside the session.
-
tmux kill-session -t workCaution: closes the work session and all the processes running in it.
-
tmux kill-session -aCaution: closes all sessions except the current one, along with their processes. Combined with -t work, only the work session stays open.
-
tmux kill-serverCaution: stops tmux completely and closes all sessions, windows, and the processes running in them, without asking for confirmation.
The prefix key
-
Ctrl+bThe tmux prefix key. Press Ctrl+b, release it, and then press the command key. For example, Ctrl+b d means Ctrl+b followed by the d key.
-
Ctrl+b ?Lists the tmux shortcuts with a short description of each. Press q to close the list.
-
Ctrl+b :Opens the tmux command prompt at the bottom of the screen. At this prompt, you type tmux commands without the word tmux, for example resize-pane -D 10.
-
Ctrl+b Ctrl+bSends Ctrl+b to the program running in the pane, for example when the program uses that key combination itself.
-
set -g prefix C-aA line in ~/.tmux.conf that sets Ctrl+a as the prefix key instead of Ctrl+b.
-
unbind C-bA line in ~/.tmux.conf that removes the Ctrl+b binding after you change the prefix key.
-
bind C-a send-prefixA line in ~/.tmux.conf that lets you send Ctrl+a to the program in the pane by pressing it twice, once it is set as the prefix key.
Windows
-
Ctrl+b cOpens a new window in the session. Each window fills the whole screen, and the status line at the bottom shows the list of windows.
-
Ctrl+b n / Ctrl+b pSwitch to the next and the previous window, respectively.
-
Ctrl+b 0...9Switches to a window by its number, from 0 to 9.
-
Ctrl+b 'Prompts for a window number and switches to that window. Useful for a window numbered higher than 9.
-
Ctrl+b lSwitches back to the window that was active before the current one.
-
Ctrl+b wShows all sessions and windows as a tree, with a preview, and lets you choose a window with the arrow keys and Enter.
-
Ctrl+b ,Renames the current window, for example to logs, so it's easy to spot in the status line.
-
Ctrl+b fSearches for text in the open windows and shows the windows where it appears.
-
tmux new-window -n logsOpens a new window named logs in the current session.
-
Ctrl+b &Caution: closes the current window and all the processes running in it, after you confirm with the y key.
Panes: split and move
-
Ctrl+b %Splits the current pane in two, left and right.
-
Ctrl+b "Splits the current pane in two, top and bottom.
-
Ctrl+b ArrowMoves to the pane above, below, to the left, or to the right of the current pane, according to the arrow key.
-
Ctrl+b oMoves to the next pane in the window.
-
Ctrl+b ;Moves back to the pane that was active before the current one.
-
Ctrl+b qBriefly shows the number of each pane. Press a number while it is displayed to move to that pane.
-
Ctrl+b zZooms the current pane to fill the whole window and temporarily hides the other panes. Press it again to restore the previous layout.
-
Ctrl+b { / Ctrl+b }Swap the current pane with the previous pane and with the next pane, respectively.
-
Ctrl+b Ctrl+oRotates the panes in the window, so each pane moves to the position of the next one.
-
Ctrl+b SpaceSwitches to the next preset pane layout, for example panes side by side, stacked, or in a grid.
-
Ctrl+b !Breaks the current pane out of the window and opens it as a separate window.
-
Ctrl+b xCaution: closes the current pane and the process running in it, after you confirm with the y key.
Resizing panes
-
Ctrl+b Ctrl+ArrowResizes the current pane by one cell in the direction of the arrow.
-
Ctrl+b Alt+ArrowResizes the current pane by five cells in the direction of the arrow.
-
:resize-pane -D 10At the tmux command prompt: moves the bottom border of the pane 10 lines down. The -U option resizes upward, -L to the left, and -R to the right.
-
:resize-pane -x 50%At the tmux command prompt: sets the pane width to half the window width. The -y option sets the height the same way, and you can also give a number of cells without the % sign.
Scrolling, search, and copy (copy mode)
-
Ctrl+b [Enters copy mode, where you can scroll back through the pane's output, search it, and copy from it. The program in the pane keeps running while you are in copy mode.
-
Ctrl+b PageUpEnters copy mode and immediately scrolls one page up.
-
qExits copy mode and returns to the end of the output. With emacs-style keys (the default), Escape also exits.
-
PageUp / PageDownEmacs style: scroll one page up and one page down. In vi style, the keys are Ctrl+b and Ctrl+f, and in both styles the arrow keys move the cursor.
-
Alt+< / Alt+>Emacs style: go to the start and to the end of the history. In vi style, the keys are g and G.
-
Ctrl+s / Ctrl+rEmacs style: search forward and backward as you type. In vi style, type / to search forward or ? to search backward, followed by the text and Enter.
-
nMoves to the next match of the last search, in both styles.
-
Ctrl+SpaceEmacs style: starts a selection at the cursor position, and moving the cursor extends it. In vi style, the Space key starts the selection.
-
Alt+wEmacs style: copies the selected text and exits copy mode. In vi style, the Enter key copies.
-
Ctrl+b ]Pastes the text most recently copied in copy mode into the current pane.
-
tmux show-options -gw mode-keysShows which key style is active in copy mode, emacs or vi. The default is emacs, unless the VISUAL or EDITOR variable contains vi.
Synchronized panes and saving output
-
:setw synchronize-panes onAt the tmux command prompt: everything you type is sent to all panes in the window, for example to run the same command on several servers connected over SSH in different panes. Caution: before you press Enter, check that the command is right for every pane.
-
:setw synchronize-panes offAt the tmux command prompt: stops the synchronization, and typing goes only to the current pane again.
-
tmux capture-pane -p -S - > ~/pane-output.txtSaves the entire output of the current pane to a file, including the history that has already scrolled off the screen. Run it from inside the pane whose output you want to save.
-
tmux capture-pane -p -J -S -200 -t workShows the last 200 lines of history of the active pane in the work session, along with the visible part of the screen, from outside the session. The -J option joins long lines that were wrapped on screen.
The ~/.tmux.conf configuration file
-
set -g mouse onTurns on mouse support: clicking selects a pane or window, dragging a border resizes a pane, and the mouse wheel scrolls through the history. With mouse support on, your terminal's regular copy usually requires holding Shift while you select.
-
set -g history-limit 10000Sets how many lines of history are kept for each pane. A very high value increases memory use, and in older tmux versions the change applies only to new panes.
-
set -g base-index 1Starts window numbering at 1 instead of 0, so the first window is on the 1 key at the left of the keyboard.
-
setw -g pane-base-index 1Starts pane numbering at 1 as well.
-
setw -g mode-keys viSets vi-style keys in copy mode, for example Space to start a selection and Enter to copy.
-
bind % split-window -h -c "#{pane_current_path}"Changes Ctrl+b % so the new pane opens in the current pane's directory, instead of the directory where the session was started.
-
bind '"' split-window -v -c "#{pane_current_path}"Changes Ctrl+b " the same way, for a top and bottom split.
-
tmux source-file ~/.tmux.confReloads the configuration file after you edit it, without closing your sessions. Inside tmux, you can press Ctrl+b : and type source-file ~/.tmux.conf.
No matching items.
Sessions, windows, and panes
tmux runs your terminal inside a session that is kept on the server. When the SSH connection drops, the session keeps running, and so does an update, a file copy, or a long script running in it. After you reconnect, you run tmux attach and pick up exactly where you left off. Each session can have several windows, and in each window you can split the screen into several panes, for example editing a file in one pane while following a log in another.
How to read the shortcuts on this page
Almost every tmux shortcut starts with the prefix key Ctrl+b. Press it, release it, and only then press the next key. The word Arrow stands for one of the arrow keys. Commands that start with a colon are typed at the tmux command prompt, which opens with Ctrl+b :, without the colon. The lines in the last category go in the ~/.tmux.conf file in your home directory, and they are loaded the next time tmux starts or right away with tmux source-file ~/.tmux.conf.
Detaching with Ctrl+b d leaves the session running, while the exit command in the last pane of the session closes it. General commands for working on a server are on the Linux commands page.
On a Linux VPS, you connect over SSH with full root access, so you can install tmux and use it to run updates, backups, and long tasks that keep running even when the connection from your computer drops.
tmux commands and shortcuts FAQ
What are the benefits of tmux when working on a server?
tmux keeps your work environment on the server itself. A long-running command, such as a system update or a large file copy, keeps running even when your SSH connection drops or you shut down your computer, and you can get back to it from any computer. On top of that, a single connection lets you open several windows and split the screen into panes, for example editing a configuration file next to the service log.
How do I get back to a session after my SSH connection drops?
Connect to the server again and run tmux ls to see the active sessions, and then run tmux attach -t followed by the session name, for example tmux attach -t work. When only one session is running, tmux attach is enough. The tmux new -A -s work command attaches to the session if it exists and creates it if it doesn't.
How do I scroll back through the output in tmux?
Press Ctrl+b followed by [ to enter copy mode, and then scroll with the arrow keys or with PageUp and PageDown. The Ctrl+b PageUp shortcut enters copy mode and immediately scrolls one page up, and the q key takes you back to the regular screen. When you add the line set -g mouse on to ~/.tmux.conf, you can also scroll with the mouse wheel.
Can I change the Ctrl+b prefix key?
Yes. Add the lines set -g prefix C-a, unbind C-b, and bind C-a send-prefix to ~/.tmux.conf, and load the file with tmux source-file ~/.tmux.conf. From then on, all shortcuts start with Ctrl+a instead of Ctrl+b.
What is the difference between a session, a window, and a pane in tmux?
A session is a complete work environment that keeps running on the server even when no terminal is attached to it. Each session can have several windows, and each window fills the whole screen, like tabs in a browser. A window can be split into several panes, and each pane is a separate terminal shown next to the others.