完成翻译

This commit is contained in:
su-kaiyao 2014-08-14 22:51:11 +08:00
parent 9c3b688909
commit 7864ab19f1
2 changed files with 152 additions and 148 deletions

View File

@ -1,148 +0,0 @@
[su-kaiyao]翻译中
How to improve your productivity in terminal environment with Tmux
================================================================================
The introduction of the mouse was a wonderful innovation in making computers more accessible to average people. But for programmers and sysadmins, moving our hands off the keyboard while working on a computer can be distracting.
As a sysadmin, I spend most of the time working in the terminal environment. Opening tabs and moving around windows through multiple terminals slows me down, and I just can't waste any second when something is going really wrong with my server.
![](https://farm6.staticflickr.com/5563/14853747084_e14cf18e8f_z.jpg)
[Tmux][1] is one of those tools that are essential for my daily work. With Tmux, I can create complex development environments, and have SSH connections side by side. I can create multiple windows, split panes, attach and detach sessions, etc. After mastering Tmux, you will throw out your mouse away ( just kidding don't do it :D ).
Tmux (short for "Terminal Multiplexer") lets us launch multiple terminals in a flexible layout on a single screen, so that we can work with them side by side. For example, on one pane we can edit some config files with Vim, while on the other we are using irssi to chat and on other pane, tailing some logs. Then open another window to update your system, and another to SSH to some servers. Navigating through them is just as easy as creating all these windows and panes. It is perfectly configurable and customizable so it can become an extension of your mind.
### Install Tmux on Linux/OSX ###
You can install Tmux by compiling it from sources or via your operating system package manager. I recommend you to use a package manager. It's faster and easier than compiling.
#### OSX: ####
# sudo brew install tmux
# sudo port install tmux
#### Debian/Ubuntu: ####
$ sudo apt-get install tmux
RHEL/CentOS/Fedora (RHEL/CentOS require [EPEL repo][2]):
$ sudo yum install tmux
Archlinux:
$ sudo pacman -S tmux
### Working with Different Sessions ###
The best way to use Tmux is working with sessions, so that you can organize your tasks and applications into different sessions the way you want. If you need to change a session, whatever runs inside the session won't stop or get killed. Let's see how it works.
Let's start a new session named "session", and run top command in it.
$ tmux new -s new session
$ top
then type **CTRL-b d** to detach from this session. To re-attach to it:
$ tmux attach-session -t session
And you will see top still running in the re-attached session.
Some commands to manage sessions:
$ tmux list-session
$ tmux new-session <session-name>
$ tmux attach-session -t <session-name>
$ tmux rename-session -t <session-name>
$ tmux choose-session -t <session-name>
$ tmux kill-session -t <session-name>
### Working with Different Windows ###
Often you will need to run multiple commands and perform different tasks in a session. We can organize all of them on multiple windows in one session. A window can be seen as a tab on modern GUI terminal (such iTerm, or Konsole). After configuring our default environment in a session, we will be able to create as many windows as we would need within the same session. Windows, like our apps running in sessions, persist when we detach from the current session. Let's check out an example:
$ tmux new -s my_session
![](https://farm6.staticflickr.com/5583/14853747014_442b3742fa_z.jpg)
Press **CTRL-b c**
This will create a new window and move focus into it. Now you can start up another application in the new window. You can write down the name of your current window. In this case I was running top so that's the window's name.
To rename it just type:
**CTRL-b** ,
The status bar changes to let you rename the current window.
![](https://farm6.staticflickr.com/5579/14855868482_d52516a357_z.jpg)
Once we create multiple windows in a session, we need a way to move through them. Windows are organized as an array, so every window has a number starting at 0. To jump quickly to other windows:
**CTRL-b <window number>**
If we have named our windows, we can look for them with:
**CTRL-b f**
and to list all windows:
**CTRL-b w**
and to move to a different window one by one:
**CTRL-b n** (go to the next window)
**CTRL-b p** (go to the previous window)
To leave a window, just type exit or:
**CTRL-b &**
You have to confirm if you want to kill off the window.
### Splitting a Window into Panes ###
Sometimes you need to type in your editor and check a log at the same time, and having your editor and tail side by side is really useful. With Tmux, we can divide a window into multiple panes. So for example, we can create a dashboard to monitor our servers and a complex development environment with the editor, the compiler and debugger running together side by side.
Let's create another Tmux session to work with panes. First let's detach from any Tmux session in case we are in a running session.
**CTRL-b d**
Start a new session named "panes".
$ tmux new -s panes
You can split a window horizontally or vertically. Let's start horizontally by pressing:
**CTRL-b** "
Now you have two new panes. Now vertically by pressing:
**CTRL-b** %
and now two more:
![](https://farm4.staticflickr.com/3881/14669677417_bc1bdce255_z.jpg)
To move through them:
**CTRL-b <Arrow keys>**
### Conclusion ###
I hope this tutorial has been helpful to you. As a bonus, tools such as [Tmuxinator][3] or [Tmuxifier][4] can streamline the process of creating and loading Tmux sessions, windows and panes, so that you can configure Tmux easily. Check them out if you haven't.
--------------------------------------------------------------------------------
via: http://xmodulo.com/2014/08/improve-productivity-terminal-environment-tmux.html
作者:[Christopher Valerio][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/valerio
[1]:http://tmux.sourceforge.net/
[2]:http://xmodulo.com/2013/03/how-to-set-up-epel-repository-on-centos.html
[3]:https://github.com/tmuxinator/tmuxinator
[4]:https://github.com/jimeh/tmuxifier

View File

@ -0,0 +1,152 @@
如何使用Tmux提高终端环境下的生产率
===
鼠标的采用是次精彩的创新,它让电脑更加接近普通人。但从程序员和系统管理员的角度,使用电脑办公时,手一旦离开键盘,就会有些分心
作为一名系统管理员,我大量的工作都需要在终端环境下。打开很多标签,然后在多个终端之间切换窗口会让我慢下来。而且当我的服务器出问题的时候,我不能浪费任何时间
![](https://farm6.staticflickr.com/5563/14853747084_e14cf18e8f_z.jpg)
[Tmux][1]是我日常工作必要的工具之一。我可以借助Tmux创造出复杂的开发环境同时还可以在一旁进行SSH远程连接。我可以开出很多窗口拆分成很多面板附加和分离会话等等。掌握了Tmux之后你就可以扔掉鼠标了只是个玩笑:D
Tmux("Terminal Multiplexer"的简称)可以让我们在单个屏幕的灵活布局下开出很多终端我们就可以协作地使用它们。举个例子在一个面板中我们用Vim修改一些配置文件在另一个面板我们使用irssi聊天而在其余的面板跟踪一些日志。然后我们还可以打开新的窗口来升级系统再开一个新窗口来进行服务器的ssh连接。在这些窗口面板间浏览切换和创建它们一样简单。它的高度可配置和可定制的让其成为你心中的延伸
### 在Linux/OSX下安装Tmux ###
你可以通过编译软件源或者通过系统包管理器的方式安装,我建议使用包管理器,这样比编译更快更简单
#### OSX: ####
# sudo brew install tmux
# sudo port install tmux
### Debian/Ubuntu ###
# sudo apt-get install tmux
RHEL/CentOS/Fedora(RHEL/CentOS 要求 [EPEL repo][2]):
$ sudo yum install tmux
Archlinux:
$ sudo pacman -S tmux
### 使用不同会话工作 ###
使用Tmux的最好方式是使用不同的会话这样你就可以以你想要的方式将任务和应用组织到不同的会话中。如果你想改变一个会话会话里面的任何工作都无须停止或者杀掉让我们来看看这是怎么工作的
让我们开始一个叫做"session"的会话并且运行top命令
$ tmux new -s new session
$ top
然后输入**CTRL-b d**从此会话脱离,想要重新连接此会话,需输入:
$ tmux attach-session -t session
之后你会看到top操作仍然运行在重新连接的会话上
一些管理sessions的命令
$ tmux list-session
$ tmux new-session <session-name>
$ tmux attach-session -t <session-name>
$ tmux rename-session -t <session-name>
$ tmux choose-session -t <session-name>
$ tmux kill-session -t <session-name>
### 使用不同的窗口工作
很多情况下你需要在一个会话中运行多个命令并且执行多个任务。我们可以在一个会话的多个窗口里组织他们。在现代化的GUI终端比如 iTerm或者Konsole一个窗口被视为一个标签。在会话中配置了我们默认的环境我们就能够在一个会话中创建许多我们需要的窗口。窗口就像运行在会话中的应用程序当我们脱离当前会话的时候它仍在持续让我们来看一个例子
$ tmux new -s my_session
![](https://farm6.staticflickr.com/5583/14853747014_442b3742fa_z.jpg)
按下**CTRL-b c**
这将会创建一个新的窗口然后屏幕的光标移向它。现在你就可以在新窗口下运行你的新应用。你可以写下你当前窗口的名字。在目前的案例下我运行的top程序所以top就是该窗口的名字
如果你想要重命名,只需要按下:
**CTRL-b**
状态条将会改变,这时你将可以重命名当前的窗口
![](https://farm6.staticflickr.com/5579/14855868482_d52516a357_z.jpg)
一旦在一个会话中创建多个窗口,我们需要在这些窗口间移动的办法。窗口以数组的形式被组织在一起,每个窗口都有一个从0开始计数的号码,想要快速跳转到其余窗口:
**CTRL-b <window number>**
如果我们给窗口起了名字,我们可以使用下面的命令切换:
**CTRL-b f**
列出所有窗口:
**CTRL-b w**
按照顺序切换到不同的窗口:
**CTRL-b n**(到达下一个窗口)
**CTRL-b p**(到达上一个窗口)
想要离开一个窗口:
**CTRL-b &**
关闭窗口之前,你需要确认一下
### 把窗口分成许多面板
有时候你在编辑器工作的同时需要查看日志文件。编辑的同时追踪日志真的很有帮助。Tmux可以让我们把窗口分成许多面板。举了例子我们可以创建一个控制台监测我们的服务器同时拥有一个复杂的编辑器环境这样就能同时进行编译和debug
让我们创建另一个Tmux会话让其以面板的方式工作。首先如果我们在某个会话中那就从Tmux会话中脱离出来
**CTRL-b d**
开始一个叫做"panes"的新会话
$ tmux new -s panes
你可以水平或者竖直分割一个窗口,水平分割输入:
**CRTL-b "**
现在你就拥有两个面板,现在我们竖直分割:
**CRTL-b %**
又增加了两个
![](https://farm4.staticflickr.com/3881/14669677417_bc1bdce255_z.jpg)
在他们之间移动:
**CTRL-b <Arrow keys>**
### 结论
我希望这篇教程能对你有作用。作为奖励,像[Tmuxinator][3] 或者 [Tmuxifier][4]这样的工具可以简化Tmux会话窗口和面板的创建及加载你可以很容易就配置Tmux。如果你没有使用过这些尝试一下吧
--------------------------------------------------------------------------------
via: http://xmodulo.com/2014/08/improve-productivity-terminal-environment-tmux.html
作者:[Christopher Valerio][a]
译者:[su-kaiyao](https://github.com/su-kaiyao)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/valerio
[1]:http://tmux.sourceforge.net/
[2]:http://xmodulo.com/2013/03/how-to-set-up-epel-repository-on-centos.html
[3]:https://github.com/tmuxinator/tmuxinator
[4]:https://github.com/jimeh/tmuxifier