In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The content of this article mainly focuses on how to use Tmux easily. The content of the article is clear and clear. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!
Tmux is a terminal multiplexer (terminal multiplexer), which is very useful and is a commonly used development tool.
What is Tmux?
1.1 sessions and processes
A typical use of the command line is to open a terminal window (terminal window, hereinafter referred to as "window") and enter commands in it. This temporary interaction between the user and the computer is called a "session".
An important feature of a session is that the window is connected to the process started in it. Open the window, the session begins; close the window, the session ends, and the process within the session terminates, whether it is finished or not.
A typical example is when SSH logs in to a remote computer and opens a remote window to execute commands. At this time, the network is suddenly disconnected, and when you log in again, you can't find the last command you executed. Because the last SSH session was terminated, the processes in it disappeared.
To solve this problem, the session and the window can be "unbound": when the window is closed, the session does not terminate, but continues to run, and then let the session "bind" other windows when needed later.
1.2 the role of Tmux
Tmux is the "unbinding" tool for sessions and windows, separating them completely.
(1) it allows multiple sessions to be accessed simultaneously in a single window. This is useful for running multiple command line programs at the same time.
(2) it allows a new window to "access" an existing session.
(3) it allows multiple connection windows per session, so multiple people can share the session in real time.
(4) it also supports any vertical and horizontal split of the window.
A similar terminal multiplexer also has GNU Screen. Tmux is similar in function, but easier to use and more powerful.
II. Basic usage
2.1 installation
Tmux generally needs to be installed on its own.
# Ubuntu or Debian$ sudo apt-get install tmux# CentOS or Fedora$ sudo yum install tmux# Mac$ brew install tmux
2.2 start and exit
After the installation is complete, type the tmux command to enter the Tmux window.
$tmux
The above command launches the Tmux window with a status bar at the bottom. On the left side of the status bar is the window information (number and name), and on the right is the system information.
Picture
Press Ctrl+d or explicitly enter the exit command to exit the Tmux window.
$exit
2.3 prefix key
The Tmux window has a large number of shortcut keys. All shortcuts are evoked by prefix keys. The default prefix key is Ctrl+b, that is, press Ctrl+b before the shortcut key will take effect.
For example, the shortcut key for the help command is Ctrl+b? Its use is that in the Tmux window, press Ctrl+b first, and then press?, and the help message will be displayed.
Then, press ESC or Q to exit the help.
III. Session management
3.1 New session
The first launched Tmux window is numbered 0, the second window is numbered 1, and so on. The corresponding sessions of these windows are session 0 and session 1.
It is not intuitive to use numbers to distinguish sessions, and a better way is to name the sessions.
$tmux new-s
The above command creates a new session with the specified name.
3.2 detach session
In the Tmux window, pressing Ctrl+b d or typing the tmux detach command will separate the current session from the window.
$tmux detach
After the above command is executed, the current Tmux window is exited, but the session and the processes in it are still running in the background.
The tmux ls command can view all current Tmux sessions.
$tmux ls# or$ tmux list-session
3.3 access session
The tmux attach command is used to reconnect to an existing session.
# use session number $tmux attach-t conversation use session name $tmux attach-t
3.4 Kill session
The tmux kill-session command is used to kill a session.
# use session number $tmux kill-session-t conversation use session name $tmux kill-session-t
3.5 switching session
The tmux switch command is used to switch sessions.
# use session number $tmux switch-t conversation use session name $tmux switch-t
3.6 rename the session
The tmux rename-session command is used to rename sessions.
$tmux rename-session-t 0
The above command renames session 0.
3.7 session shortcuts
Here are some session-related shortcut keys.
Ctrl+b d: detach the current session. Ctrl+b s: lists all sessions. Ctrl+b $: rename the current session.
Fourth, the simplest operation flow
To sum up, the following is the simplest operation flow of Tmux.
Create a new session tmux new-s my_session. Run the required program in the Tmux window. Press the shortcut key Ctrl+b d to separate the session. Next time you use it, reconnect to the session tmux attach-session-t my_session.
Fifth, pane operation
Tmux can divide a window into multiple panes (pane), each running a different command. The following commands are executed in the Tmux window.
5.1 divide the pane
The tmux split-window command is used to divide panes.
# divide upper and lower panes $tmux split-window# divide left and right panes $tmux split-window-h
Picture
5.2 move the cursor
The tmux select-pane command is used to move the cursor position.
# cursor switch to the upper pane $tmux select-pane-U# cursor switch to the lower pane $tmux select-pane-D# cursor switch to the left pane $tmux select-pane-L# cursor switch to the right pane $tmux select-pane-R
5.3 Exchange Pane location
The tmux swap-pane command is used to exchange pane positions.
# current pane moves up $tmux swap-pane-U# current pane moves down $tmux swap-pane-D
5.4 pane shortcut key
Here are some keyboard shortcuts for pane operations.
Ctrl+b%: divide the left and right panes. Ctrl+b ": divides the upper and lower panes. Ctrl+b: the cursor switches to another pane. Is the arrow key that points to the pane you want to switch to. For example, if you switch to the lower pane, press the direction key ↓. Ctrl+b;: the cursor switches to the previous pane. Ctrl+b o: the cursor switches to the next pane. Ctrl+b {: the current pane moves to the left. Ctrl+b}: the current pane moves to the right. Ctrl+b Ctrl+o: the current pane moves up. Ctrl+b Alt+o: the current pane moves down. Ctrl+b x: closes the current pane. Ctrl+b!: splits the current pane into a separate window. Ctrl+b z: the current pane is displayed in full screen. If you use it again, it will change back to its original size. Ctrl+b Ctrl+: resizes the panes in the direction of the arrows. Ctrl+b Q: displays the pane number.
VI. Window management
In addition to dividing a window into multiple panes, Tmux also allows you to create multiple windows.
6.1 New window
The tmux new-window command is used to create new windows.
$tmux new-window# create a new window with the specified name $tmux new-window-n
6.2 switch window
The tmux select-window command is used to switch windows.
# switch to window with specified number $tmux select-window-t # switch to window with specified name $tmux select-window-t
6.3 rename window
The tmux rename-window command is used to name (or rename) the current window.
$tmux rename-window
6.4 window shortcuts
Here are some shortcut keys for window operations.
Ctrl+b c: create a new window, and the status bar displays information about multiple windows. Ctrl+b p: switch to the previous window (in the order on the status bar). Ctrl+b n: switch to the next window. Ctrl+b: switch to the window with the specified number, where is the window number on the status bar. Ctrl+b w: select a window from the list. Ctrl+b,: rename the window.
VII. Other orders
Here are some other commands.
# list all keyboard shortcuts and their corresponding Tmux commands $tmux list-keys# list all Tmux commands and their parameters $tmux list-commands# list information about all current Tmux sessions $tmux info# reload the current Tmux configuration $tmux source-file ~ / .tmux.conf Thank you for reading, I believe you have some understanding of the problem of "how to make Tmux easy to use", go and practice If you want to know more about it, you can follow the website! The editor will continue to bring you better articles!
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.