Share your love
How To Install and Use tmux on Linux
In this guide from the Linux Tutorials, we intend to teach you How To Install and Use tmux on Linux.
The `screen` package is deprecated and not included in RHEL 8. But you can use the tmux package instead of the screen.
Tmux is a Linux application that allows multitasking in a terminal window. It stands for Terminal Multiplexing and is based around sessions. Users can start a process, switch to a new one, detach from a running process, and reattach to a running process.
Some users like Tmux better and some are more comfortable with Screen. Tmux, however, is deemed more user-friendly than the other. On the other hand, Screen allows a user to share a session with other users but this feature is missing in Tmux.
Steps To Install and Use tmux on Linux
To complete this guide, you must log in to your server as a non-root user with sudo privileges. You can use any Linux distro.
Install tmux on Linux
The tmux packages are available in the default repositories.
To install tmux on Centos 7 and RHEL 7, you can use the command below:
sudo yum install tmux
You can use the command below to install tmux on Debian and Ubuntu:
sudo apt install tmux
To install tmux on RHEL 8, you can use the command below:
sudo dnf -y install tmux
When your installation is completed, you can verify it by checking the tmux version:
tmux -V
Example Output
tmux 2.7
Work with tmux on Linux
In Tmux, you will be working with sessions, windows, and panes.
- Sessions define the general task at hand. For example, if you are testing something, stick to a single session for all activities related to your test.
- Windows are for specific activities or projects within a session.
- Panes help you create multiple views within one window. For example, you might be working on something in one pane, and using the other to track error logs.
Use tmux panes, windows, and sessions to organize your tasks in a logical manner.
Start a New Session in tmux
To start a new session in tmux, simply type the following command in your Linux terminal:
tmux
Once you are in tmux, the only thing that will be visibly different is the ever-present green bar at the bottom.
Now you can run your tmux commands in your session. For example, use the following command to get a list of all commands:
Ctrl+b ?
Note: tmux command usage may differ from version to version. Your Linux tmux version might not support all of the commands listed below. For more information see the official tmux changelog.
Name Linux tmux Sessions
To start a new session with a specific name in tmux, you can use the following command in your Linux terminal:
tmux new -s [name of session]
Split Pane tmux
In a GUI desktop environment, you have windows. In tmux, you have panes. Like windows in a GUI, these panes allow you to interact with multiple applications and similarly can be opened, closed, resized, and moved.
Tmux allows splitting the screen both horizontally and vertically.
Split the screen horizontally: CTRL+b+"
Split the screen vertically: CTRL+b+%
Resize Panes
You can change the size of each pane. To do so, press CTRL+b+:
.
The bottom bar will change from green to yellow. Now you can type a command to resize the Linux tmux pane:
1.resize-pane -D
– Moves the boundary line for the pane downward.
2.resize-pane -U
– Moves the boundary line for the pane upward.
3.resize-pane -R
– Moves the boundary line for the pane right.
4.resize-pane -L
– Moves the boundary line for the pane left.
You may also specify a specific number of cells to move the boundary line. For example:
resize-pane -U 10
– Moves the boundary line up 10 cells.
You can specify a different cell than the one you’re working in. To resize Cell 2 (lower right):
resize-pane –t 2 --R 5
– Moves the boundary line 5 cells to the right.
Detach and Reattach tmux Sessions
With tmux, you can keep a process working in the background.
To detach from the current session, you can use:
tmux detach
Your system will drop to a normal command line. There should be an output that reads [detached (from session X)]
.
To reattach the session, you can use:
tmux attach
The system will re-enter the live Linux tmux session, and pick up just where you left off.
To attach to a specifically named session, use:
tmux a -t session_name
List Active tmux Sessions
You can easily list your tmux active session by using the command below:
tmux ls
Example Output
0: 1 windows (created Sat Nov 12 03:55:44 2022) [80x23] (attached)
Work with tmux Window Screens
Your screen can become cluttered if you have too many panes open. You can create a new full-screen window by entering CTRL+b+c
.
To rename a window, switch to it and use the comma key: CTRL+b+,
You can simply switch to the next window by pressing: CTRL+b+n
To switch to the previous window press: CTRL+b+p
You can display an interactive list of windows with CTRL+b+w
.
Use the up/down arrow keys to select the window you want to use, then press enter.
Also, you can close a tmux window, by using the: CTRL+b+&
Configure tmux on Linux
The tmux is so highly configurable. You can edit the tmux.conf file to make changes.
To create custom changes for a single user, create the file in the user’s home directory ~/.tmux.conf. To create system-wide changes, create the file in the system directory /etc/tmux.conf.
Change Activation Key
By default, tmux uses the CTRL+b
combination to activate functions. To do this, open the file with your favorite text editor, here we use vi:
sudo vi /etc/tmux.conf
Add the following lines to the file:
unbind C-b
set –g prefix C-a
Save the changes and exit. Now, whenever you use tmux, you’ll use CTRL+a
to activate functions.
Note: If you have any active tmux sessions, the changes won’t take effect until they are closed and restarted. Detaching will not work.
Change Status Bar Appearance
Open the configuration file for editing:
sudo vi /etc/tmux.conf
Add the following lines to the file:
# Status bar colors
set –g status-bg blue
set –g status-fg black
# highlight and display
setw –g monitor-activity on
setw –g visual-activity on
Save the changes and exit the file.
Conclusion
At this point, you have learned to Install and Use tmux on Linux.
Hope you enjoy it.
You may be like these articles: