In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use tmux in linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Tmux is an acronym for terminal multiplexer terminal multiplexer, which allows users to create or enable multiple terminals (vertical or horizontal) in a single window, which can be easily accessed and controlled in a single window when you are dealing with different problems.
It uses the client-server model to allow sessions to be shared between users and to connect terminals to tmux sessions. We can easily move or rearrange the virtual console as needed. Terminal sessions can be freely switched from one virtual console to another.
Tmux relies on libevent and ncurses libraries. Tmux provides a status line at the bottom of the screen that displays information about the current tmux session, such as the current window number, window name, user name, hostname, current time, and date.
When you start tmux, it creates a new session on a separate window and displays it on the screen. It allows users to create any number of windows in the same session.
Many people say it is similar to screen, but I don't think so, because it provides a lot of configuration options.
Note: Ctrl+b is the default command prefix in tmux, so to perform any action in tmux, you must first enter the prefix and then enter the desired options.
Tmux characteristics
Create any number of windows
Create any number of panes in a window
It allows vertical and horizontal segmentation.
Detach and reconnect the window
Client-server architecture, which allows users to share sessions
Tmux provides many configuration tips
How to install the tmux command
Most Linux systems preinstall the tmux command by default. If not, follow these steps to install.
For Debian/Ubuntu, use the APT-GET command or the APT command to install:
$sudo apt install tmux
For RHEL/CentOS, use the YUM command to install:
$sudo yum install tmux
For Fedora, use the DNF command to install:
$sudo dnf install tmux
For Arch Linux, use the Pacman command to install:
$sudo pacman-S tmux
For openSUSE, use the Zypper command to install:
$sudo zypper in tmux how to use tmux
Run the following command on the terminal to start the tmux session. After starting tmux, it will create a new session in a new window and will automatically log in to your default shell using your user account.
$tmux
You will get a screenshot similar to the one above. Tmux comes with a status bar that displays details about the current session, date, time, and so on.
The status bar information is as follows:
[0]: this represents the session number created by the tmux server. By default, it starts at 0.
0:bash: represents the session number, the command line prompt (where bash represents the shell name).
*: this means that the window is now active.
Hostname: displays the full hostname of the server.
Date and time: displays the current date and time.
(LCTT translation note: the status of tmux can be customized according to needs, and it also varies from environment to environment and version. )
How to split a window
Tmux allows users to split windows vertically or horizontally, called panes. Each pane contains its own terminal instance that runs independently. Let's see how to do this.
Press Ctrl+b,% to split the pane vertically.
Press Ctrl+b to split the pane horizontally.
How to move between panes
Suppose we create some panes and want to move between them. What should we do? If you don't know what to do, there's no point in using tmux. Use the following control keys to perform the action. There are many ways to move between panes.
Press Ctrl+b, ←-Select the left pane
Press Ctrl+b, →-Select the right pane
Press Ctrl+b, ↑-Select the upper pane
Press Ctrl+b, ↓-Select the lower pane
Press Ctrl+b, {- to swap the pane to the left
Press Ctrl+b,}-to swap the pane to the right
Press Ctrl+b, o-to switch to the next pane (left to right, top to bottom)
Press Ctrl+b,;-move to the previously active pane
For testing purposes, we will move between panes. Now we are in pane2, which shows the output of the lsb_release-a command.
We will move to pane0, which displays the output of the uname-a command.
How to open / create a new window
You can open any number of windows in a terminal.
Press Ctrl+b, c to create a new window.
Press Ctrl+b, n to move to the next window.
Press Ctrl+b, p to move to the previous window.
Press Ctrl+b, 0-Ctrl+b, 9 to move to a specific window immediately.
Press Ctrl+b, l to move to the previously selected window.
I have two windows, and the first window has three panes that contain operating system version information, top command output, and kernel information.
The second window has two panes that contain logo information for the Linux distribution. Use the following command to perform the action:
Press Ctrl+b, w to select the current window interactively.
How to zoom the pane
You are working in some very small panes, and you want to shrink them for further work. To do this, use the following key binding.
We currently have three panes. I work at pane1, which uses the top command to display system activity information, and I will zoom it.
When you zoom a pane, it hides all other panes and displays only the zoom panes in the window.
Press Ctrl+b, z to zoom the pane, and press it again to restore the zoom pane to its original state.
Display pane information
To understand the pane number and its size, run the following command.
Press Ctrl+b, Q to simply display the pane index.
Display window information
To know the window number, layout size, the number and size of panes associated with the window, run the following command.
Simply run tmux list-windows to view the window information.
How to resize the pane
You may need to resize the panes to meet your requirements. You must press Ctrl+b,:, and enter the following details on the yellow bar at the bottom of the page.
In the previous section, we printed the pane index, which also shows the pane size. In order to test, we need to add 10 units to. Referring to the following output, this pane increases the size of pane1 and pane2 from 55x21 to 55x31.
Syntax: Ctrl+b,: then enter resize-pane [options] [cells size]
Ctrl+b,: then type resize-pane-D 10 to resize the current pane down 10 cells.
Ctrl+b,: then type resize-pane-U 10 to resize the current pane up 10 cells.
Ctrl+b,: then enter resize-pane-L 10 to resize the current pane 10 cells to the left.
Ctrl+b,: then enter resize-pane-R 10 to resize the current pane 10 cells to the right.
Detach and reconnect the tmux session
One of the powerful features of tmux is the ability to detach and reconnect sessions when needed.
Run a long-running process, then press Ctrl+b, and then press d to securely detach your tmux session by leaving the running process.
Recommended reading: how to keep the process / command running after disconnecting the SSH session
Now run a long-running process. For demonstration purposes, we will move this server backup to another remote server for disaster recovery (DR).
$rsync-avzhe ssh / backup root@192.168.0.161:/backups/week-1/
After detaching the tmux session, you will get output similar to the following.
[detached (from session 0)]
Run the following command to list the available tmux sessions.
$tmux ls0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45]
Now, reconnect to the tmux session using the appropriate session ID, as follows:
$tmux attach-t 0 how to close panes and windows
Just type exit in the appropriate pane or press Ctrl-d to close it, similar to terminal shutdown. To close the window, press Ctrl+b, &.
The above is all the contents of the article "how to use tmux in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.