Note:
- This tutorial is available in an Oracle-provided free lab environment.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Learn to Use the tmux Terminal Multiplexer on Oracle Linux
Introduction
This tutorial provides step-by-step procedures for controlling multiple terminal windows in the same persistent session.
By default, terminating your SSH connection also terminates any remote terminal sessions started by that connection. If you use a terminal multiplexer, you can preserve those sessions for yourself and others to reuse. You can also manage more complex tasks from a single SSH connection, as a terminal multiplexer can provide browser-style tabs for each task, and even divide up your screen with multiple terminal sessions called “panes”.
In previous versions of Oracle Linux, you might have encountered a similar tool called screen
, but in this tutorial you will explore tmux
. This tutorial is targeted at users of Oracle Linux 8 or later.
Objectives
Upon completion of this Lab you will be able to:
- Connect and disconnect from a persistent tmux session
- Display, hide, and switch between multiple terminals in the same tmux session
- Manage several persistent tmux sessions
What do you need?
- Any system with Oracle Linux 8
Install the tmux Terminal Multiplexer
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
Install the tmux
package on your instance by using the package manager, as follows:
sudo dnf install -y tmux
Start and connect to a tmux session
Note: tmux sessions are not preserved between reboots, so they are best suited for persistent remote servers.
The tmux
command rearranges your terminal window, with a green band running along the bottom that lists the currently active panes. By default, sessions and panes are ordered numerically, according to dynamically assigned ID numbers that count upwards from zero.
All tmux sessions are hosted in a background service, so that means you can reconnect to them if your connection times out, or if your user account has previously logged off.
- Start
tmux
without any parameters to create a new session and connect to it:
tmux
- List your currently open
tmux
sessions:
tmux ls
- Detach by pressing Ctrl+b, and then the d key.
- Reattach to your persistent
tmux
session:
tmux attach -t 0
You can run tmux ls
from inside or outside tmux to verify which sessions are available for you to reopen.
Manage multiple tmux sessions
Note: You cannot create nested tmux sessions by default, so always ensure that you have detached from your current tmux session before attempting to create or connect to any other tmux sessions.
- Rename your existing session to
oracle
:
tmux rename-session -t 0 oracle
- Detach by pressing Ctrl+b, and then the d key.
- Create a new tmux session called
oracletemp
:
tmux new -t oracletemp
- Detach by pressing Ctrl+b, and then the d key.
- List your open sessions:
tmux ls
- Reconnect to the
oracle
session:
tmux attach -t oracle
Manage terminal window panes
Terminal window panes behave much like web browser tabs, where you can create, delete, and switch between them. Unlike a web browser, you must use keyboard shortcuts to perform those actions.
- Create a new terminal window by pressing Ctrl+b, and then the c key.
- Switch to the next window by pressing Ctrl+b, and then the n key. You should notice an asterisk move between each numbered tab as you switch.
- Switch to the previous window by pressing Ctrl+b, and then the p key.
- Switch to the second window by pressing Ctrl+b, and then then the 1 key.
- Close the second window by pressing Ctrl+b, and then the ampersand (&) key. Confirm the action.
- Rename the first window by pressing Ctrl+b, and then the comma (,) key. Set the new name to
lab
.
Manage split terminal window panes
You can split the current terminal window pane to suit your workflow. For example, you could input commands on one half of the terminal pane, and review the output for those commands on the other half.
- You can split the current pane vertically by pressing Ctrl+b, and then the modulo (%) key.
- You can split the current pane horizontally by pressing Ctrl+b, and then the quotation mark (“) key.
- You can switch between split panes by pressing Ctrl+b, and then the direction keys on your keyboard.
- You can close any of the panes by pressing Ctrl+b, and then the x key. Confirm the action.
Reconnect to a tmux session over SSH
- Detach by pressing Ctrl+b, and then the d key.
- Run the
exit
command to end the SSH connection. - Press the up direction key, and then reuse the command you previously executed to start a new SSH connection:
ssh oracle@<IP_ADDRESS_OF_COMPUTE_INSTANCE>
- Reconnect to your tmux session:
tmux attach -t oracle
Terminate tmux sessions
- List your sessions:
tmux ls
- Detach by pressing Ctrl+b, and then the d key.
- Terminate your sessions.
-
Terminate the
oracletemp
session:tmux kill-session -t oracletemp
-
Terminate every
tmux
session simultaneously with a single command:tmux kill-server
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Learn to Use the tmux Terminal Multiplexer on Oracle Linux
F45234-06
May 2022
Copyright © 2021, Oracle and/or its affiliates.