Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use tmux to build a more powerful terminal under Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use tmux to create a more powerful terminal under Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Install and start tmux

The name of a tmux application comes from a terminal (terminal) multiplexer (muxer) or a multiplexer (multiplexer). In other words, it can divide your single-terminal session into multiple sessions. It manages windows and panes:

A window is a single view-that is, the various things displayed in the terminal.

The pane is part of the view, which is usually a terminal session.

Before you begin, install the tmux application on your system. You need to set sudo permissions for your user account (see this article for instructions if necessary).

Sudo dnf-y install tmux

Run the tmux program:

Tmux

Status bar

First, nothing seems to happen, except for the status bar at the bottom of the terminal:

Start of tmux session

The bottom bar shows:

[0]-this is the * session created by the tmux server. The number starts at 0. The tmux server tracks all sessions to see if they are alive.

0RV testusername scarlettParse ~-information about the * windows of the session. The number starts at 0. This means that the terminals in the active pane of the window are owned by the testuser user in the hostname scarlett. The current directory is ~ (home directory).

*-shows that you are currently in this window.

"scarlett.internal.fri"-the hostname of the tmux server you are using.

"in addition, the date and time on that particular host are displayed."

As you add more windows and panes to the session, the information bar will change.

Basic knowledge of tmux

Stretch your terminal window to *. Now let's try some simple commands to create more panes. By default, all commands start with Ctrl+b.

Tap Ctrl+b, "split the current single pane horizontally. There are now two command line panes in the window, one at the top and one at the bottom. Notice that the new pane at the bottom is the active pane.

Click Ctrl+b to split the current single pane vertically. Now there are three command line panes in your window, and the lower right pane is the active pane.

Tmux window with three panes

Notice the highlighted border around the current pane. To browse all the panes:

Tap Ctrl+b, and then click the arrow key

Tap Ctrl+b, Q, and the number will appear briefly on the pane. In the meantime, you can browse the corresponding numbers on the pane you want to browse.

Now, try running different commands using different panes. For example, the following:

Use the ls command to display the contents of the directory in the top pane.

Use the vi command in the lower left pane to edit a text file.

Run the top command in the lower right pane to monitor the system process.

The screen will be displayed as follows:

Tmux session with three panes running different commands

So far, only one window with multiple panes has been used in this example. You can also run multiple windows in a session.

To create a new window, click Ctrl+b, c. Notice that the status bar shows that there are two windows currently running. (the keen reader will see the screenshot above.)

To move to the previous window, click Ctrl+b, p.

To move to the next window, click Ctrl+b, n.

To move to a specific window immediately, click Ctrl+b and follow the window number.

If you want to know how to close the pane, just use exit, logout, or Ctrl+d to exit a specific command line shell. Once you close all the panes in the window, the window will also disappear.

Detach and attach

One of the great features of tmux is the ability to detach and reattach to a session. When you leave, you can leave your windows and panes to run independently. In addition, you can even log out of the system completely. You can then log in to the same system, reattach to the tmux session, and view all windows and panes when you leave. The command you run remains running when you leave it.

To break away from a conversation, please Ctrl+b, d. Then the session disappears and you return to a standard single shell. If you want to reattach to the session, use the following command:

Tmux attach-session

This function is as useful as a lifeguard when the network you connect to the host is unstable. If the connection fails, all processes in the session continue to run. As long as the connection is restored, you can return to normal as if nothing had happened.

If these features are not enough, you can run multiple sessions in the top-level windows and panes of each session. You can list these windows and panes and append them to the correct session by number or name:

This is the end of tmux list-sessions 's article on "how to use tmux to create a more powerful terminal under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report