Merge pull request #12121 from MjSeven/20180130

翻译完成 20180130 tmux...
This commit is contained in:
Xingyu.Wang 2019-01-25 00:21:10 +08:00 committed by GitHub
commit d40dd1e2b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 263 additions and 262 deletions

View File

@ -1,262 +0,0 @@
Translating by MjSeven
tmux A Powerful Terminal Multiplexer For Heavy Command-Line Linux User
======
tmux stands for terminal multiplexer, it allows users to create/enable multiple terminals (vertical & horizontal) in single window, this can be accessed and controlled easily from single window when you are working with different issues.
It uses a client-server model, which allows you to share sessions between users, also you can attach terminals to a tmux session back. We can easily move or rearrange the virtual console as per the need. Terminal sessions can freely rebound from one virtual console to another.
tmux depends on libevent and ncurses libraries. tmux offers status-line at the bottom of the screen which display information about your current tmux session suc[]h as current window number, window name, username, hostname, current time, and current date.
When tmux is started it creates a new session with a single window and displays it on screen. It allows users to create Any number of windows in the same session.
Many of us says it's similar to screen but i'm not since this offers wide range of configuration options.
**Make a note:** `Ctrl+b` is the default prefix in tmux so, to perform any action in tumx, you have to type the prefix first then required options.
**Suggested Read :** [List Of Terminal Emulator For Linux][1]
### tmux Features
* Create any number of windows
* Create any number of panes in the single window
* It allows vertical and horizontal splits
* Detach and Re-attach window
* Server-client architecture which allows users to share sessions between users
* tmux offers wide range of configuration hacks
**Suggested Read :**
**(#)** [tmate - Instantly Share Your Terminal Session To Anyone In Seconds][2]
**(#)** [Teleconsole - A Tool To Share Your Terminal Session Instantly To Anyone In Seconds][3]
### How to Install tmux Command
tmux command is pre-installed by default in most of the Linux systems. If no, follow the below procedure to get installed.
For **`Debian/Ubuntu`** , use [APT-GET Command][4] or [APT Command][5] to install tmux.
```
$ sudo apt install tmux
```
For **`RHEL/CentOS`** , use [YUM Command][6] to install tmux.
```
$ sudo yum install tmux
```
For **`Fedora`** , use [DNF Command][7] to install tmux.
```
$ sudo dnf install tmux
```
For **`Arch Linux`** , use [Pacman Command][8] to install tmux.
```
$ sudo pacman -S tmux
```
For **`openSUSE`** , use [Zypper Command][9] to install tmux.
```
$ sudo zypper in tmux
```
### How to Use tmux
kick start the tmux session by running following command on terminal. When tmux is started it creates a new session with a single window and will automatically login to your default shell with your user account.
```
$ tmux
```
[![][10]![][10]][11]
You will get similar to above screenshot like us. tmux comes with status bar which display an information's about current sessions details, date, time, etc.,.
The status bar information's are below:
* **`0 :`** It is indicating the session number which was created by the tmux server. By default it starts with 0.
* **`0:username@host: :`** 0 is indicating the session number. Username and Hostname which is holding the current window.
* **`~ :`** It is indicating the current directory (We are in the Home directory)
* **`* :`** This indicate that the window is active now.
* **`Hostname :`** This shows fully qualified hostname of the server
* **`Date& Time:`** It shows current date and time
### How to Split Window
tmux allows users to split window vertically and horizontally. Let 's see how to do that.
Press `**(Ctrl+b), %**` to split the pane vertically.
[![][10]![][10]][13]
Press `**(Ctrl+b), "**` to split the pane horizontally.
[![][10]![][10]][14]
### How to Move Between Panes
Lets say, we have created few panes and want to move between them. How to do that? If you don 't know how to do, then there is no purpose to use tmux. Use the following control keys to perform the actions. There are many ways to move between panes.
Press `(Ctrl+b), Left arrow` - To Move Left
Press `(Ctrl+b), Right arrow` - To Move Right
Press `(Ctrl+b), Up arrow` - To Move Up
Press `(Ctrl+b), Down arrow` - To Move Down
Press `(Ctrl+b), {` - To Move Left
Press `(Ctrl+b), }` - To Move Right
Press `(Ctrl+b), o` - Switch to next pane (left-to-right, top-down)
Press `(Ctrl+b), ;` - Move to the previously active pane.
For testing purpose, we are going to move between panes. Now, we are in the `pane2` which shows `lsb_release -a` command output.
[![][10]![][10]][15]
And we are going to move to `pane0` which shows `uname -a` command output.
[![][10]![][10]][16]
### How to Open/Create New Window
You can open any number of windows within one terminal. Terminal window can be split vertically & horizontally which is called `panes`. Each pane will contain its own, independently running terminal instance.
Press `(Ctrl+b), c` to create a new window.
Press `(Ctrl+b), n` move to the next window.
Press `(Ctrl+b), p` to move to the previous window.
Press `(Ctrl+b), (0-9)` to immediately move to a specific window.
Press `(Ctrl+b), l` Move to the previously selected window.
I have two windows, first window has three panes which contains operating system distribution information, top command output & kernal information.
[![][10]![][10]][17]
And second window has two panes which contains Linux distributions logo information. Use the following commands perform the action.
[![][10]![][10]][18]
Press `(Ctrl+b), w` Choose the current window interactively.
[![][10]![][10]][19]
### How to Zoom Panes
You are working in some pane which is very small and you want to zoom it out for further work. To do use the following key binds.
Currently we have three panes and i'm working in `pane1` which shows system activity using **Top** command and am going to zoom that.
[![][10]![][10]][17]
When you zoom a pane, it will hide all other panes and display only the zoomed pane in the window.
[![][10]![][10]][20]
Press `(Ctrl+b), z` to zoom the pane and press it again, to bring the zoomed pane back.
### Display Pane Information
To know about pane number and it's size, run the following command.
Press `(Ctrl+b), q` to briefly display pane indexes.
[![][10]![][10]][21]
### Display Window Information
To know about window number, layout size, number of panes associated with the window and it's size, etc., run the following command.
Just run `tmux list-windows` to view window information.
[![][10]![][10]][22]
### How to Resize Panes
You may want to resize the panes to fit your requirement. You have to press `(Ctrl+b), :` then type the following details on the `yellow` color bar in the bottom of the page.
[![][10]![][10]][23]
In the previous section we have print pane index which shows panes size as well. To test this we are going to increase `10 cells UPward`. See the following output that has increased the pane1 & pane2 size from `55x21` to `55x31`.
[![][10]![][10]][24]
**Syntax:** `(Ctrl+b), :` then type `resize-pane [options] [cells size]`
`(Ctrl+b), :` then type `resize-pane -D 10` to resize the current pane Down for 10 cells.
`(Ctrl+b), :` then type `resize-pane -U 10` to resize the current pane UPward for 10 cells.
`(Ctrl+b), :` then type `resize-pane -L 10` to resize the current pane Left for 10 cells.
`(Ctrl+b), :` then type `resize-pane -R 10` to resize the current pane Right for 10 cells.
### Detaching and Re-attaching tmux Session
One of the most powerful features of tmux is the ability to detach and reattach session whenever you need.
Run a long running process and press `Ctrl+b` followed by `d` to detach your tmux session safely by leaving the running process.
**Suggested Read :** [How To Keep A Process/Command Running After Disconnecting SSH Session][25]
Now, run a long running process. For demonstration purpose, we are going to move this server backup to another remote server for disaster recovery (DR) purpose.
You will get similar output like below after detached tmux session.
```
[detached (from session 0)]
```
Run the following command to list the available tmux sessions.
```
$ tmux ls
0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45]
```
Now, re-attach the tmux session using an appropriate session ID as follow.
```
$ tmux attach -t 0
```
### How to Close Panes & Window
Just type `exit` or hit `Ctrl-d` in the corresponding pane to close it. It's similar to terminal close. To close window, press `(Ctrl+b), &`.
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/tmux-a-powerful-terminal-multiplexer-emulator-for-linux/
作者:[Magesh Maruthamuthu][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.2daygeek.com/author/magesh/
[1]:https://www.2daygeek.com/category/terminal-emulator/
[2]:https://www.2daygeek.com/tmate-instantly-share-your-terminal-session-to-anyone-in-seconds/
[3]:https://www.2daygeek.com/teleconsole-share-terminal-session-instantly-to-anyone-in-seconds/
[4]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
[5]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
[6]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
[8]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
[9]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[11]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-1.png
[13]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-2.png
[14]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-3.png
[15]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-4.png
[16]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-5.png
[17]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-8.png
[18]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-6.png
[19]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-7.png
[20]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-9.png
[21]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-10.png
[22]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-14.png
[23]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-11.png
[24]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-13.png
[25]:https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/

View File

@ -0,0 +1,263 @@
tmux - 适用于重度命令行 Linux 用户的强大终端复用器
======
tmux 是终端复用的缩写,它允许用户在单个窗口中创建或启用多个终端(垂直或水平),当你处理不同的问题时,可以在单个窗口中轻松访问和控制。
它使用客户端-服务器模型,允许用户之间共享会话,也可以将终端连接到 tmux 会话。我们可以根据需要轻松移动或重新排列虚拟控制台。终端会话可以从一个虚拟控制台自由切换到另一个。
tmux 依赖于 `libevent``ncurses` 库。tmux 在屏幕底部提供了一个状态行,它显示当前 tmux 会话的有关信息,例如当前窗口编号,窗口名称,用户名,主机名,当前时间和日期。
启动 tmux 时,它会在一个单独窗口上创建一个新的会话,并将其显示在屏幕上。它允许用户在同一个会话中创建任意数量的窗口。
许多人说它相当于一块屏幕,但我不这么认为,因为它提供了许多配置选项。
**注意:** `Ctrl+b` 是 tmux 中的默认前缀,因此,要在 tmux 中执行任何操作,你必须先输入前缀然后输入所需的选项。
**建议阅读:** [适用于 Linux 的终端仿真器列表][1]
### tmux 特性
* 创建任意数量的窗口
* 在一个窗口中创建任意数量的窗格
* 它允许垂直和水平分割
* 分离并重新连接窗口
* 客户端-服务器架构,这允许用户之间共享会话
* tmux 提供许多配置技巧
**建议阅读:**
**(#)** [tmate - 马上与其他人分享你的终端会话][2]
**(#)** [Teleconsole - 一个与其他人分享终端会话的工具][3]
### 如何安装 tmux 命令
大多数 Linux 系统默认预安装 tmux 命令。如果没有,按照以下步骤安装。
对于 **`Debian/Ubuntu`**,使用 [APT-GET 命令][4]或 [APT 命令][5]来安装:
```
$ sudo apt install tmux
```
对于 **`RHEL/CentOS`**,使用 [YUM 命令][6]来安装:
```
$ sudo yum install tmux
```
对于 **`Fedora`**,使用 [DNF 命令][7]来安装:
```
$ sudo dnf install tmux
```
对于 **`Arch Linux`**,使用 [Pacman 命令][8]来安装:
```
$ sudo pacman -S tmux
```
对于 **`openSUSE`**,使用 [Zypper 命令][9]来安装:
```
$ sudo zypper in tmux
```
### 如何使用 tmux
在终端上运行以下命令来启动 tmux 会话。启动 tmux 后,它会在一个新窗口中创建新会话,并将使用你的用户账户自动登录到你的默认 shell。
```
$ tmux
```
![][11]
你会得到类似于我们上面的截图。tmux 附带状态栏,显示有关当前会话详细信息,日期,时间等。
状态栏信息如下:
* **`0 :`** 它表示由 tmux 服务器创建的会话号。默认情况下,它从 0 开始。
* **`0:username@host: :`** 0 表示会话号。用户名和主机名是当前的使用窗口的人。
* **`~ :`** 它表示当前目录(我们在家目录中)。
* **`* :`** 这表示窗口现在处于活动状态。
* **`Hostname :`** 显示服务器的完全主机名。
* **`Date& Time:`** 显示当前日期和时间。
### 如何拆分窗口
tmux 允许用户垂直或水平分割窗口。我们来看看如何做到这一点。
按下 `**(Ctrl+b), %**` 来垂直分割窗口。
![][13]
Press `**(Ctrl+b), "**` 来水平分割窗口。
![][14]
### 如何在窗格之间移动
假设,我们创建了一些窗格,希望在它们之间移动,这该怎么做?如果你不知道怎么做,那么使用 tmux 就没有意义了。使用以下控制键执行操作。在窗格之间移动有许多方法。
`(Ctrl+b), 左箭头` - 来向左移动
`(Ctrl+b), 右箭头` - 来向右移动
`(Ctrl+b), 上箭头` - 来向上移动
`(Ctrl+b), 下箭头` - 来向下移动
`(Ctrl+b), {` - 来向左移动
`(Ctrl+b), }` - 来向右移动
`(Ctrl+b), o` - 切换到下一个窗格(从左到右,从上到下)
`(Ctrl+b), ;` - 移动到先前活动的窗格
出于测试目的,我们将在窗格之间移动。现在我们在 `pane2` 中,它 `lsb_release -a` 命令的输出。
![][15]
我们将移动到 `pane0`,它显示 `uname -a` 命令的输出。
![][16]
### 如何打开/创建新窗口
你可以在一个终端内打开任意数量的窗口。终端窗口可以垂直和水平分割,称为 `panes`。每个窗格都包含自己独立运行的终端实例。
`(Ctrl+b), c` 来创建一个新窗口。
`(Ctrl+b), n` 移动到下一个窗口
`(Ctrl+b), p` 移动到上一个窗口。
`(Ctrl+b), (0-9)` 立即移动到特定窗口。
`(Ctrl+b), l` 移动到先前选择的窗口。
我有两个窗口第一个窗口有三个窗格其中包含操作系统版本信息top 命令输出和内核信息。
![][17]
第二个窗口有两个窗格,其中包含 Linux 发行版 logo 信息。使用以下命令执行操作:
![][18]
`(Ctrl+b), w` 以交互方式选择当前窗口。
![][19]
### 如何缩放窗格
你正在一些非常小的窗格中工作,并且你希望将其缩小以进行进一步的工作。要做到这一点,使用以下键绑定。
目前我们有三个窗格,我在 `pane1` 工作,它使用 **Top** 命令显示系统活动信息,我将缩放它。
![][17]
缩放窗格时,它将隐藏所有其它窗格,并只显示窗口中的缩放窗格。
![][20]
`(Ctrl+b), z` 缩放窗格并再次按下它,使缩放窗格恢复原状。
### 显示窗格信息
要了解窗格编号及其大小,运行以下命令。
`(Ctrl+b), q` 可简单显示窗格索引。
![][21]
### 显示窗口信息
要知道窗口编号,布局大小,与窗口关联的窗格数量及其大小等,运行以下命令。
只需运行 `tmux list-windows` 即可查看窗口信息。
![][22]
### 如何调整窗格大小
你可能需要调整窗格大小来满足你的要求。你必须按下 `(Ctrl+b), :`,然后在页面底部的 `黄色(yellow)` 颜色条上输入以下详细信息。
![][23]
在上一部分中,我们有打印了窗格索引,它同时也显示了窗格大小。为了测试,我们要向上增加 `10` 个单元。参考以下输出,该窗格将 pane1 和 pane2 的大小从 `55x21` 增加到 `55x31`
![][24]
**语法:** `(Ctrl+b), :` 然后输入 `resize-pane [options] [cells size]`
`(Ctrl+b), :` 然后输入 `resize-pane -D 10` 将当前窗格大小向下调整 10 个单元。
`(Ctrl+b), :` 然后输入 `resize-pane -U 10` 将当前窗格大小向上调整 10 个单元。
`(Ctrl+b), :` 然后输入 `resize-pane -L 10` 将当前窗格大小向左调整 10 个单元。
`(Ctrl+b), :` 然后输入 `resize-pane -R 10` 将当前窗格大小向右调整 10 个单元。
### 分离并重新连接 tmux 会话
tmux 最强大的功能之一是能够在需要时分离和重新连接会话。
运行一个长时间运行的进程,然后按下 `Ctrl+b`,接着按 `d`,通过离开正在运行的进程安全地分离你的 tmux 会话。
**建议阅读:** [如何在断开 SSH 会话后保持进程/命令继续运行][25]
现在运行一个长时间运行的进程。出于演示目的我们将把此服务器备份移动到另一个远程服务器以进行灾难恢复DR
```
$ rsync -avzhe ssh /backup root@192.168.0.161:/backups/week-1/
```
在分离 tmux 会话之后,你将获得类似下面的输出。
```
[detached (from session 0)]
```
运行以下命令以列出可用的 tmux 会话。
```
$ tmux ls
0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45]
```
现在,使用适当的会话 ID 重新连接 tmux 会话,如下所示:
```
$ tmux attach -t 0
```
### 如何关闭窗格和窗口
只需在相应的窗格中输入 `exit` 或按下 `Ctrl-d` 即可关闭它,和终端关闭类似。要关闭窗口,按下 `(Ctrl+b), &`
好了,就到这里了,希望你喜欢上它。
(to 校正:这句话是加的,感觉它结尾很突然,可以删掉。)
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/tmux-a-powerful-terminal-multiplexer-emulator-for-linux/
作者:[Magesh Maruthamuthu][a]
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.2daygeek.com/author/magesh/
[1]:https://www.2daygeek.com/category/terminal-emulator/
[2]:https://www.2daygeek.com/tmate-instantly-share-your-terminal-session-to-anyone-in-seconds/
[3]:https://www.2daygeek.com/teleconsole-share-terminal-session-instantly-to-anyone-in-seconds/
[4]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
[5]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
[6]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
[8]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
[9]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[11]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-1.png
[13]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-2.png
[14]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-3.png
[15]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-4.png
[16]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-5.png
[17]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-8.png
[18]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-6.png
[19]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-7.png
[20]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-9.png
[21]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-10.png
[22]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-14.png
[23]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-11.png
[24]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-13.png
[25]:https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/