linux tmux_Linux Tmux教程与示例

linux  tmux

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
Install Tmux
安装Tmux

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
Tmux Man
特曼人

启动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
Start Tmux
启动Tmux

绑定密钥 (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
List Current Key Bindings
列出当前的键绑定

启动新窗口(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
New Window
新窗户

移动下一个窗口(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
Move Next Window
移动下一个窗口

After switching the asterisk which shows the current desktop will put a new window afterward.

切换显示当前桌面的星号后,之后将放一个新窗口。

LEARN MORE  How To Restart CentOS, Fedora, RedHat?
了解更多如何重启CentOS,Fedora,RedHat?

移动上一个窗口 (Move the Previous Window)

This is similar to moving the next window. Just type following keyboard shortcut.

这类似于移动下一个窗口。 只需输入以下键盘快捷键即可。

CTRL+b p
Move Previous Window
Move the Previous Window
移动上一个窗口

移至指定的窗口编号(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
Rename Window Name
重命名窗口名称

什么是窗格?(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
Tmux Pane
Tmux窗格

创建新的垂直窗格(Create New Vertical Pane)

The current window can be divided into two vertical panes with the CTRL+b %.

当前窗口可以使用CTRL+b %分为两个垂直窗格。

CTRL+b %
Vertical Pane
Vertical Pane
垂直窗格

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
New Horizontal Pane
新水平窗格

在窗格之间移动和导航(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
Show Pane Numbers
显示窗格编号

关闭窗格(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提供了一些不同的复制粘贴方法。 通常可以使用控制台提供的复制粘贴,但是如果源是多行文本,则可能无法正确复制。 以下是复制文本的步骤。

LEARN MORE  How To Get Centos, Fedora, Red Hat Release Version?
了解更多信息如何获得Centos,Fedora,Red Hat发行版本?

开始复印模式 (Start Copy Mode)

CTRL+b [
Copy Mode
Copy Mode
复制模式

设定起点(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
Copy Mode
复制模式

设定终点(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
Tmux Paste
Tmux粘贴

建立工作阶段(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
Create Session
建立工作阶段

列出会议(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
List Sessions
列出会议

分离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
Detach Tmux
分离Tmux

重新连接 (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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值