![linux tmux](https://i-blog.csdnimg.cn/blog_migrate/d52cf5034aeb17dfb3cbe59664110af5.png)
linux tmux
Tmux is a terminal multiplexer popular in Linux world. Tmux provides multiple windows in a single session. Tmux also has the ability to detach and run after disconnect and attach after connection. This is very useful for system administrators.
Tmux是在Linux世界中流行的终端多路复用器。 Tmux在单个会话中提供多个窗口。 Tmux还具有在断开连接后分离并运行并在连接后连接的能力。 这对于系统管理员非常有用。
什么是Tmux? (What Is Tmux?)
Tmux is described as terminal multiplexer. This terms means a single terminal can be used like multiple terminal. Tmux is based command line interface where there is no need to run a graphical interface. Tmux can provide multiple windows like different pages and each window may have single or multiple panes which divides current window visually.
Tmux被描述为终端多路复用器。 这个术语意味着可以像多个终端一样使用单个终端。 Tmux是基于命令行的界面,无需运行图形界面。 Tmux可以提供多个窗口,例如不同的页面,并且每个窗口可以具有单个或多个窗格,这些窗格在视觉上划分了当前窗口。
Tmux的优势和用例 (Tmux Advantages and Usecases)
Tmux is a popular tool between system administrators and geeks with its lifesaver features. Tmux provides the following advantages and uses cases that make it superior to other terminals.
Tmux具有救生功能,是系统管理员和极客之间流行的工具。 Tmux具有以下优点,并且使用案例使其优于其他终端。
- Tmux can run multiple sessions at the same time. Tmux可以同时运行多个会话。
- Even SHH or remote connection drops Tmux can continue reconnecting existing sessions. 甚至SHH或远程连接断开,Tmux都可以继续重新连接现有会话。
- Tmux can be used run commands continuously even the connection lost. 即使失去连接,也可以连续使用Tmux运行命令。
- Tmux can be managed completely with key shortcuts. Tmux可以通过快捷键进行完全管理。
- Tmux requires very very low system resources. Tmux需要非常低的系统资源。
安装Tmux (Install Tmux)
Installation of the tmux is very easy on Linux distributions like Ubuntu, Debian, Mint, Kali, Fedora, CentOS, RHEL etc.
在Linux发行版(例如Ubuntu,Debian,Mint,Kali,Fedora,CentOS,RHEL等)上安装tmux非常容易。
Ubuntu, Debian, Mint, Kali:
Ubuntu,Debian,Mint,Kali :
$ sudo apt install tmux
![](https://i-blog.csdnimg.cn/blog_migrate/6112eb10d03ad652c75d392c126bac56.png)
Fedora, CentOS, RHEL:
Fedora,CentOS,RHEL:
$ sudo dnf install tmux
Tmux手册页 (Tmux Man Page)
The manpage of tmux provides a lot of detailed features. To get more information man page of tmux can be used like below.
tmux的手册页提供了许多详细功能。 要获取更多信息,可以如下使用tmux的手册页。
$ man tmux
![Tmux Man](https://i-blog.csdnimg.cn/blog_migrate/065898dac0b4768a60aa1afb9315cb99.png)
启动Tmux(Start Tmux)
Tmux is a terminal emulator that acts as a shell. Tmux can be started as a shell too. Just run tmux command we will get tmux screen by clearing the existing shell screen.
Tmux是充当外壳程序的终端仿真器。 Tmux也可以作为外壳启动。 只需运行tmux命令,我们将通过清除现有的shell屏幕来获取tmux屏幕。
$ tmux
![Start Tmux](https://i-blog.csdnimg.cn/blog_migrate/b3aa967ae145910359a529d6752ff13c.png)
绑定密钥 (Bind Key)
Tmux uses CTRL+b for operation key which means to use shortcuts of tmux CTRL+b should be prefixed with the related keyboard shortcut.
Tmux使用CTRL + b作为操作键,这意味着要使用tmux的快捷键,CTRL + b应该带有相关的键盘快捷键。
CTRL+b
列出当前的键绑定 (List Current Key Bindings)
Tmux mainly used with keys with bind keys. These key bindings can be listed with the following command. As we can see from the following screenshot there are a lot of key bindings provided by tmux.
Tmux主要用于带有绑定键的键。 可以使用以下命令列出这些键绑定。 从下面的屏幕快照中可以看到,tmux提供了很多键绑定。
CTRL+b :list-keys
![List Current Key Bindings](https://i-blog.csdnimg.cn/blog_migrate/4b5c9c54967b08a3e4785896f9fa4f5d.png)
启动新窗口(Start New Window)
One of the most useful functionalities of the tmux is operating multiple windows. Existing windows are listed in the green bar below. Creating a new window will create a new shell like a new tab in terminal emulators.
tmux最有用的功能之一是操作多个窗口。 现有的窗口在下面的绿色栏中列出。 创建一个新窗口将在终端仿真器中创建一个新外壳,例如一个新选项卡。
CTRL+b c
![New Window](https://i-blog.csdnimg.cn/blog_migrate/1acdae8d53c9c4f300e76a8f51201180.png)
移动下一个窗口(Move Next Window)
While working with multiple windows navigation between windows can be done in different ways. One of the most common usages is switching the next window with the following key short cut.
在使用多个窗口时,可以以不同的方式在窗口之间导航。 最常见的用法之一是使用以下快捷键切换下一个窗口。
CTRL+b n
![Move Next Window](https://i-blog.csdnimg.cn/blog_migrate/18e684358e353c06f42d72216d5761e8.png)
After switching the asterisk which shows the current desktop will put a new window afterward.
切换显示当前桌面的星号后,之后将放一个新窗口。
移动上一个窗口 (Move the Previous Window)
This is similar to moving the next window. Just type following keyboard shortcut.
这类似于移动下一个窗口。 只需输入以下键盘快捷键即可。
CTRL+b p
![Move Previous Window](https://i-blog.csdnimg.cn/blog_migrate/a8fcc1e4205b797ec10837ceae3d7180.png)
移至指定的窗口编号(Move To The Specified Window Number)
Another useful navigation feature is using window number to navigate. Window numbers can be seen below of the terminal before the window name.
另一个有用的导航功能是使用窗口编号进行导航。 可以在终端下方窗口名称之前看到窗口编号。
CTRL+b <number of window>
重命名窗口 (Rename Window)
Normally tmux sets current running application name as window name. If we are using a lot of windows for multiple operations and we want to rename the window name.
通常,tmux将当前正在运行的应用程序名称设置为窗口名称。 如果我们将许多窗口用于多个操作,并且想重命名窗口名称。
CTRL+b ,
![Rename Window Name](https://i-blog.csdnimg.cn/blog_migrate/ac1868746d93177bd8d7b528fa13cc0c.png)
什么是窗格?(What Is Pane?)
The pane is used to multiplexing a single window. Using multiple commands in a single-window is very useful and popular usage. Below we can see two horizontal pane. We will look at how to create panes below.
该窗格用于多路复用单个窗口。 在单个窗口中使用多个命令是非常有用且流行的用法。 在下面我们可以看到两个水平窗格。 我们将在下面查看如何创建窗格。
![Tmux Pane](https://i-blog.csdnimg.cn/blog_migrate/2d86380a38091f1817d0b7d6e5585d46.png)
创建新的垂直窗格(Create New Vertical Pane)
The current window can be divided into two vertical panes with the CTRL+b %
.
当前窗口可以使用CTRL+b %
分为两个垂直窗格。
CTRL+b %
![Vertical Pane](https://i-blog.csdnimg.cn/blog_migrate/2d86380a38091f1817d0b7d6e5585d46.png)
After creating a pane current working pane will change to the new pane and active pane can be seen in the line between panes. The lower part of the line is yellow which means left pane is active.
创建窗格后,当前工作窗格将更改为新窗格,并且可以在窗格之间的行中看到活动窗格。 该行的下部为黄色,表示左侧窗格处于活动状态。
新水平窗格 (New Horizontal Pane)
Horizontal pane can be created with CTRL+b "
.
可以使用CTRL+b "
创建水平窗格。
CTRL+b "
![New Horizontal Pane](https://i-blog.csdnimg.cn/blog_migrate/de702eab6203e3720406b79ba4b55958.png)
在窗格之间移动和导航(Move and Navigate Between Panes)
To move between panes direction keys can be used like below.
要在窗格之间移动,可以如下使用方向键。
向左移动窗格 (Move Left Pane)
CTRL+b <left arrow>
向右移动窗格 (Move Right Pane)
CTRL+b <right arrow>
移动到窗格下方 (Move Below Pane)
CTRL+b <down arrow>
移动上窗格 (Move Upper Pane)
CTRL+b <up arrow>
显示窗格编号 (Show Pane Numbers)
While working multiple pane it can be useful to show pane numbers. Pane numbers can be shown according to their location with the command below. While showing pane number in the upper left corner of the pane the size is also shown.
在使用多个窗格时,显示窗格编号可能很有用。 可以使用以下命令根据其位置显示窗格号。 在窗格的左上角显示窗格编号时,还会显示大小。
CTRL+b q
![Show Pane Numbers](https://i-blog.csdnimg.cn/blog_migrate/352b32aea944cc2667f222872896f2ab.png)
关闭窗格(Close Pane)
If we have finished our job with a pane we generally close it to make things clean. We can close the current pane with the following shortcut.
如果我们用窗格完成工作,则通常将其关闭以使事情整洁。 我们可以使用以下快捷方式关闭当前窗格。
CTRL+d
OR
要么
:exit
复制文字 (Copy Text)
One of the most important features is copying and pasting text from the terminal. Tmux provides a bit different method to copy-paste. Normally console provided copy paste can be used but if the source is multiline text it can be impossible to copy properly. Below are the steps to copy the text.
最重要的功能之一是从终端复制和粘贴文本。 Tmux提供了一些不同的复制粘贴方法。 通常可以使用控制台提供的复制粘贴,但是如果源是多行文本,则可能无法正确复制。 以下是复制文本的步骤。
开始复印模式 (Start Copy Mode)
CTRL+b [
![Copy Mode](https://i-blog.csdnimg.cn/blog_migrate/167cd04373cfc8f99473c6918c09c44b.png)
设定起点(Set Start Point)
We can move the cursor to the start of the copy range in the copy mode and after that to set the starting point following command is used.
我们可以在复制模式下将光标移动到复制范围的起点,然后使用以下命令设置起点。
CTRL+<space>
![Copy Mode](https://i-blog.csdnimg.cn/blog_migrate/71a044c97a59156165269af3578d7342.png)
设定终点(Set End Point)
Move the cursor and we see can see the current selection is in orange color. To set endpoint and copy the contents to the buffer use following command.
移动光标,我们可以看到当前选择为橙色。 要设置端点并将内容复制到缓冲区,请使用以下命令。
ALT+w
糊 (Paste)
Copied text will be put into the buffer. We can use this text wherever we want. We can also access this text in tmux from different windows.
复制的文本将被放入缓冲区。 我们可以在任何需要的地方使用此文本。 我们还可以从不同的窗口在tmux中访问此文本。
CTRL+b ]
![Tmux Paste](https://i-blog.csdnimg.cn/blog_migrate/c7168143498f6580626f1115d6c8d6bb.png)
建立工作阶段(Create Session)
Creating a tmux session is just starting tmux. But we can also provide some parameters like the name.
创建tmux会话只是启动tmux。 但是我们也可以提供一些参数,例如名称。
$ tmux new -s mysession
![Create Session](https://i-blog.csdnimg.cn/blog_migrate/2ff64214a769844bd01d419ff8fc8e3d.png)
列出会议(List Sessions)
There may be more than one tmux sessions. These sessions can be listed with the following command.
可能有不止一个tmux会话。 可以使用以下命令列出这些会话。
CTRL+b s
![List Sessions](https://i-blog.csdnimg.cn/blog_migrate/911ecd2f4f7c9cfdfaf156a00f64dc00.png)
分离Tmux(Detach Tmux)
The existing session can be detached like below. This will not end the session thus this will only detach session from the current shell and it will continue running in the background.
现有的会话可以如下分离。 这不会结束会话,因此只会将会话与当前shell分离,并且它将继续在后台运行。
CTRL+b d
![Detach Tmux](https://i-blog.csdnimg.cn/blog_migrate/588822d59b7518ecd0eb08ce37071755.png)
重新连接 (Reattach)
Attaching session means reconnecting currently running session which is detached before.
附加会话意味着重新连接之前断开的当前正在运行的会话。
$ tmux a
配置文件 (Configuration File)
There is to path where the configuration file resides. /etc/tmux.conf
and ~/.tmux.conf
.
存在配置文件所在的路径。 /etc/tmux.conf
和~/.tmux.conf
。
翻译自: https://www.poftut.com/linux-tmux-tutorial-command-examples/
linux tmux