hankchow translated

This commit is contained in:
HankChow 2020-05-19 23:14:18 +08:00
parent c254d7f27e
commit 1b60803cda
2 changed files with 159 additions and 169 deletions

View File

@ -1,169 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (HankChow)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 ways to split your Linux terminal)
[#]: via: (https://opensource.com/article/20/5/split-terminal)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
5 ways to split your Linux terminal
======
What's your favorite terminal multiplexer? Take our poll. Then read
about how Linux offers plenty of ways for you to split your terminal so
you can multitask.
![4 different color terminal windows with code][1]
Is there anything better than a warmly flickering Linux terminal?
Sure there is: two warmly flickering Linux terminals. In fact, the more, the better.
Long ago, [terminals were physical devices][2], but of course, today, they're just emulated as an application on your computer. If you prefer the terminal as your interface, you probably know that one terminal is rarely enough. Inevitably, you're going to open a new terminal or a new tab so you can work in it while your first is busy compiling or converting or otherwise processing data.
If you're a sysadmin, then you know you're going to need at least four open windows while you work on several systems at the same time.
Terminal applications with tabs have existed on Linux for a long time, and luckily, that trend seems to have caught on such that it's an expected feature of a modern terminal. And yet, sometimes it's distracting or inconvenient to flip back and forth between tabs.
The only answer is a split screen so that two or more terminals can exist at the same time within just one application window. There are many tools in your Linux kit to help you slice and dice your consoles.
### Shells, terminals, and consoles
Before you slice and dice screens, you should know the difference between a terminal, a shell, and a "console." To get the full picture, read my article on the subject over on the [Enable Sysadmin][2] blog.
The short version:
* A shell is an input and output screen with a prompt. There's technically a shell running somewhere underneath your [POSIX][3] desktop, even when it's not visible (because it's a shell that launched your user session).
* A terminal is an application running within a graphics server (such as X11 or Wayland) with a shell loaded into it. A terminal is only running when you have a terminal window launched. It's more or less a "portal" into your shell.
* "Console" or "virtual console" is a term usually used to imply a shell running outside of your desktop. You can get to a virtual console by pressing **Alt-Ctrl-F2** (more are usually available from **F3** up to **F7**, with **F1** or **F7** representing your desktop, depending on your distribution).
Some applications let you split your shell or console, while others let you split your terminal.
### tmux
![tmux terminal][4]
Arguably the most flexible and capable of screen splitters, [tmux][5] is a keyboard-centric terminal multiplexer, meaning that you can "layer" one console on top of another and then switch between the two. You can also split a console view in half (or thirds or fourths, and so on) so you can see other consoles next to it.
All controls center around the keyboard, which means you never have to take your hand off the keys in search of a mouse, but also that you must learn some new keyboard combos.
If you're using tmux primarily for screen splitting, then the only commands you really need are these:
* **Ctrl-B %** for a vertical split (one shell on the left, one shell on the right)
* **Ctrl-B"** for a horizontal split (one shell at the top, one shell at the bottom)
* **Ctrl-B O** to make the other shell active
* **Ctrl-B ?** for help
* **Ctrl-B d** detach from Tmux, leaving it running in the background (use **tmux attach** to reenter)
There are many benefits to tmux, including the ability to start a tmux session on one computer, and then join that same session from another computer remotely. It essentially daemonizes your shell.
It's with tmux running on a Pi, for example, that I can stay logged into IRC on a permanent basis—I start tmux on the Pi, and then log in from whatever computer I happen to be on. When I log out, tmux continues to run, patiently waiting for me to reattach to the session from a different computer.
### GNU Screen
![GNU Screen terminal][6]
Similar to tmux, [GNU Screen][7] is a shell multiplexer. You can detach and reattach from a running session, and you can split the screen both horizontally and vertically.
Screen is a little clunkier than tmux. Its default key binding is **Ctrl-A**, which also happens to be Bash's keyboard shortcut to go to the beginning of a line. This means that if you have Screen running, you must press **Ctrl-A** twice instead of just once to go to the beginning of the line. Personally, I redefine the trigger key to **Ctrl-J** with this line in **$HOME/.screenrc**:
```
`escape ^jJ`
```
Screen's split function works well, but it leaves out a few pleasantries that tmux lacks. For instance, when you split your shell, a new shell does not start in the other panel. You have to navigate to the other space with **Ctrl-A Tab** (or **Ctrl-J** if you redefine your keyboard shortcut as I do) and create a new shell manually with **Ctrl-A C**.
Unlike tmux, a split doesn't go away when you exit a shell, which is a design feature that's quite nice in some instances but can also sometimes be cumbersome because it forces you to manage your splits manually.
Still, Screen is a reliable and flexible application that you can run should you find that **tmux** is unavailable to you.
Here are the basic split commands, using the default keyboard shortcuts:
* **Ctrl-A |** for a vertical split (one shell on the left, one shell on the right)
* **Ctrl-A S** for a horizontal split (one shell at the top, one shell at the bottom)
* **Ctrl-A Tab** to make the other shell active
* **Ctrl-A ?** for help
* **Ctrl-A d** detach from Screen, leaving it running in the background (use **screen -r** to reenter)
### Konsole
![Konsole screen][8]
[Konsole][9] is the terminal bundled along with the KDE Plasma desktop. Like KDE itself, Konsole is famous for being highly customizable and powerful.
Among its many features is the ability to split its window, similar to both tmux and GNU Screen. Because Konsole is a graphical terminal, you can control its split-screen feature with your mouse instead of your keyboard.
Splitting is found in the **View** menu of Konsole. You can split your window horizontally or vertically. To change which panel is active, just click on it. Each panel is a unique terminal, so it can have its own theme and tabs.
Unlike tmux and GNU Screen, you can't detach and reattach from Konsole. Like most graphical applications, you use Konsole while you're physically in front of it, and you lose access to it when you're away (unless you use remote desktop software).
### Emacs
![Emacs rpg][10]
Emacs isn't exactly a terminal multiplexer, but its interface supports splitting and resizing, and it has a built-in terminal.
If you're in Emacs on a daily basis anyway, the ability to split your window between essentially different applications means you never have to leave the familiarity and comfort of your favorite text editor. Furthermore, because the Emacs **eshell** module is implemented in eLISP, you can interact with it using the same commands you use in Emacs itself, making it trivial to copy and yank long file paths or command output.
If you're using Emacs in a graphical window, you can perform some actions with your mouse. It's faster to use keyboard shortcuts, and some are more or less required. For instance, you can change which panel is the active one by clicking into it, and you can resize the proportions of your split screen with your mouse.
These are the important keyboard shortcuts:
* **Ctrl-X 3** for a vertical split (one shell on the left, one shell on the right)
* **Ctrl-X 2** for a horizontal split (one shell at the top, one shell at the bottom)
* **Ctrl-X O** to make the other shell active (you can also do this with the mouse)
* **Ctrl-X 0** (thats a zero) close the current panel
Similar to tmux and GNU Screen, you can detach and reattach from Emacs as long as you run **emacs-client**.
### Window manager
![Ratpoison split screen][11]
Should you think a text editor that can split its screen and load a terminal is amazing, imagine your desktop serving the same purpose. There are Linux desktops, like [Ratpoison][12], [Herbsluftwm][13], i3, Awesome, and even the KDE Plasma desktop with specific settings enabled, that present each application window to you as a fixed tile in a desktop grid.
Instead of windows floating "above" your desktop, they remain in a predictable place so you can change from one to the other. You can open any number of terminals within your grid, emulating a terminal multiplexer. In fact, you could even load a terminal multiplexer in your desktop multiplexer.
And there's nothing stopping you from loading Emacs with split buffers inside of that. No one knows what happens if you take it further than that, and most Linux users agree it's best not to find out.
Unlike tmux and GNU Screen, you can't detach and reattach from your desktop unless you count using remote desktop software.
### Other options
Believe it or not, these aren't the only options you have to split your screen on Linux. There are other terminal emulators, like [Tilix][14] and Terminator before it, that can split into sections, and applications with embedded terminal components, and much more. Tell us your favorite way of splitting up your workspace in the comments.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/5/split-terminal
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freedos.png?itok=aOBLy7Ky (4 different color terminal windows with code)
[2]: https://www.redhat.com/sysadmin/terminals-shells-consoles
[3]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[4]: https://opensource.com/sites/default/files/uploads/terminal-split-tmux2.png (tmux terminal)
[5]: https://github.com/tmux/tmux
[6]: https://opensource.com/sites/default/files/uploads/terminal-split-screen.png (GNU Screen terminal)
[7]: https://www.gnu.org/software/screen/
[8]: https://opensource.com/sites/default/files/uploads/konsole.jpg (Konsole screen)
[9]: https://konsole.kde.org
[10]: https://opensource.com/sites/default/files/uploads/emacs-rpg_0.jpg (Emacs rpg)
[11]: https://opensource.com/sites/default/files/uploads/advent-ratpoison-split_0.jpg (Ratpoison split screen)
[12]: https://opensource.com/article/19/12/ratpoison-linux-desktop
[13]: https://opensource.com/article/19/12/herbstluftwm-linux-desktop
[14]: https://gnunn1.github.io/tilix-web/

View File

@ -0,0 +1,159 @@
[#]: collector: (lujun9972)
[#]: translator: (HankChow)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 ways to split your Linux terminal)
[#]: via: (https://opensource.com/article/20/5/split-terminal)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
5 种拆分 Linux 终端的方法
======
> 本文介绍了 Linux 提供的拆分终端的方法,它能够帮助你完成多任务工作。那么,你最喜欢哪一款终端复用工具呢?
![4 different color terminal windows with code][1]
没有什么问题是不能用一个 Linux 终端解决的,如果不行,那就用两个。
很早以前,[终端其实是一个物理设备][2],而现在的终端实际上是在计算机上被模拟出来的一个应用程序。当你使用终端和计算机进行交互的时候,就会发现,只打开一个终端是不够用的。在进行编译、数据处理等长时间任务的时候,你不得不打开一个新终端或新<ruby>选项卡<rt>tab</rt></ruby>来同时进行其它工作。
如果你是系统管理员,你就需要更多的终端窗口,以便连接到多个不同的主机上并行工作了。
在 Linux 系统中,终端应用程序在很久之前已经开始带有选项卡功能了。而现在的终端应用程序里,选项卡已经是标配功能了,这是非常流行的趋势。尽管如此,工作的时候在多个选项卡之间来回切换,或多或少也会分散我们的注意力,甚至带来不便。
而最好的解决方案就是将整个屏幕划分为多个部分这样多个终端就可以在同一个终端应用程序窗口中同时存在。Linux 套件中也有很多相关的工具可以实现这一功能。
### Shell、终端和控制台
在此之前,我们首先要明确 Shell、<ruby>终端<rt>terminal</rt></ruby><ruby>控制台<rt>console</rt></ruby>这三个概念。想要详细了解的话,请参阅 [Enable Sysadmin][2] 博客上的相关文章。
太长不看版:
* Shell 是带有<ruby>命令提示符<rt>prompt</rt></ruby>的用于输入、输出的界面。准确地说,[POSIX][3] 桌面底层也运行着一个 Shell无论这个 Shell 是否对用户可见,因为用户会话就是由这个 Shell 启动的。
* 终端是在图形界面服务器(例如 X11 或 Wayland中运行的应用程序其中加载了一个 Shell。只有在终端窗口启动之后才算是运行了一个终端。终端可以认为是操作 Shell 的一个入口。
* 控制台(或称“虚拟控制台”)通常表示在桌面环境以外使用的 Shell你可以通过 `Alt+Ctrl+F2` 进入控制台,通常情况下从 `F3``F7` 都是不同的控制台,其中桌面环境有可能是 `F1` 或者 `F7`,这在不同的发行版中可能会有所不同。
因此,一些应用程序提供的功能是拆分 Shell 或者控制台,一些应用程序的功能则是拆分终端。
### tmux
![tmux terminal][4]
[tmux][5] 可以说是最灵活最强大的屏幕拆分工具了,它通过键盘控制对多个终端的复用,因此你可以将一个控制台叠放在另一个控制台上面,并在两个控制台之间切换。你还可以将整个屏幕等分为多个控制台,以便同时观察不同控制台上的状况。
tmux 的所有操作都是通过键盘完成的,这就意味着你的手不需要离开键盘去寻找鼠标。为此,你需要记住一些按键组合。
如果你只用 tmux 来做屏幕拆分,那你只需要记住一下这些命令:
* `Ctrl-B %` 竖直拆分屏幕(两个 Shell 分别位于左右)
* `Ctrl-B "` 水平拆分屏幕(两个 Shell 分别位于上下)
* `Ctrl-B O` 切换到另一个 Shell
* `Ctrl-B ?` 查看帮助
* `Ctrl-B d` 断开 tmux 并让其在后台运行(可以使用 `tmux attach` 重新进入)
tmux 的一大好处是,在一台计算机上启动 tmux 会话之后也可以从另一台计算机上进入到这个会话由此可以看出tmux 对 Shell 进行了<ruby>守护<rt>daemonize</rt></ruby>
例如,当我在树莓派上运行 tmux我就可以从计算机上连接到树莓派并登录 IRC当我断开连接时树莓派上的 tmux 会继续运行,并等待我的下一次连接,在此期间 IRC 是处于持续登录状态的。
### GNU Screen
![GNU Screen terminal][6]
[GNU Screen][7] 也是一个 Shell 复用工具,类似于 tmux你可以在断开一个活动会话后重连到其中它也支持竖直或水平拆分屏幕。
Screen 的灵活性比 tmux 要弱一些。它默认的绑定按键组合是 `Ctrl-A`,和 Bash 中光标移动到行首的快捷键是一样的。因此,当你正在运行 Screen 的时候,如果想要将光标移动到行首,就需要多按一次 `Ctrl-A`。而我自己的做法是,在 `$HOME/.screenrc` 文件中将绑定按键组合重新设置为 `Ctrl-J`
```
`escape ^jJ`
```
尽管 Screen 在屏幕拆分功能上做得很好,但 tmux 上的一些缺点在 Screen 上也同样存在。例如在拆分 Shell 时,新的 Shell 不会在一个新的面板中启动,而是需要使用 `Ctrl-A Tab` 导航到另一个空间(如果你按照我的方式重新设置了按键组合,需要对应地把 `Ctrl-A` 改为 `Ctrl-J`),然后通过 `Ctrl-A C` 手动创建一个新的 Shell。
和 tmux 不同的是Screen 在推出一个 Shell 的时候,屏幕拆分状态不会改变,这样的设计在某些情况下是比较适合的,但麻烦之处在于需要手动管理屏幕拆分状态。
尽管如此Screen 还是一个相当可靠灵活的应用程序,在无法使用 tmux 的时候,你可以选择 Screen 作为备选方案。
在默认按键方案下Screen 常用的基本命令包括:
* `Ctrl-A |` 竖直拆分屏幕(两个 Shell 分别位于左右)
* `Ctrl-A S` 水平拆分屏幕(两个 Shell 分别位于上下)
* `Ctrl-A Tab` 切换到另一个 Shell
* `Ctrl-A ?` 查看帮助
* `Ctrl-A d` 断开 Screen 并让其在后台运行(可以使用 `screen -r` 重新进入)
### Konsole
![Konsole screen][8]
[Konsole][9] 是 KDE Plasma 桌面使用的终端应用程序。和 KDE 一样Konsole 也以高度可定制、功能强大的特点而著称。
和 tmux、GNU Screen 类似Konsole 也具有拆分屏幕的功能。由于 Konsole 是图形界面的终端,因此还可以用鼠标来控制它的屏幕拆分。
Konsole 的屏幕拆分功能在“<ruby>查看<rt>View</rt></ruby>”菜单中。它也支持竖直和水平方向的拆分,只要点击鼠标就可以切换到另一个面板上。每个面板都是一个独立的终端,因此都可以拥有独立的主题和标签页。
Konsole 和 tmux、GNU Screen 最大的不同之处在于不能断开和重新连接 Konsole。除非使用远程桌面软件否则只能在打开 Konsole 时使用,这一点和大多数图形界面应用程序是一样的。
### Emacs
![Emacs rpg][10]
严格来说Emacs 并不算是一个终端复用工具,但它的使用界面支持拆分和调整大小,同时还带有一个内建的终端。
如果 Emacs 是你日常使用的文本编辑器,你就可以在不关闭编辑器的情况下,在不同的应用程序之间轻松互相切换。由于 Emacs eshell 模块是通过 eLISP 实现的,因此你可以在 Emacs 中使用相同的命令进行交互,让一些繁琐的操作变得更为简单。
如果你是在图形界面中使用 Emacs还可以使用鼠标进行操作。例如通过点击切换面板、用鼠标调整拆分屏幕的的大小等等。尽管如此键盘的操作速度还是更快因此记住一些键盘快捷键还是很有必要的。
Emacs 的一些重要快捷键包括:
* `Ctrl-X 3` 竖直拆分屏幕(两个 Shell 分别位于左右)
* `Ctrl-X 2` 水平拆分屏幕(两个 Shell 分别位于上下)
* `Ctrl-X O` 切换到另一个 Shell你也可以使用鼠标操作
* `Ctrl-X 0` 关闭当前面板
如果你运行了 emacs-client 的话,就可以像 tmux 和 GNU Screen 一样断开和重新连接到 Emacs 了。
### Window manager
![Ratpoison split screen][11]
除了文本编辑器之外,一些 Linux 桌面也同样具有拆分屏幕、加载终端这样的功能。例如 [Ratpoison][12]、[Herbsluftwm][13]、i3、Awesome甚至是启用了特定设置的 KDE Plasma 桌面,都可以将多个应用程序在桌面上分块显示。
这些桌面可以让各个应用程序占据屏幕的固定位置,而不是逐个叠放在一起,因此你可以在多个应用程序窗口之间轻松切换。你还可以打开多个终端,以达到终端复用的目的。更进一步,你还可以在桌面复用工具中加载终端复用工具。
And there's nothing stopping you from loading Emacs with split buffers inside of that. No one knows what happens if you take it further than that, and most Linux users agree it's best not to find out.
和 tmux、GNU Screen 不同,你在断开与桌面的连接后无法重新连接到同一个桌面会话,除非你使用了远程桌面软件进行连接。
### 更多选择
除了上面介绍到的工具以外,还有诸如 [Tilix][14]、Terminator 这样的终端模拟器,它们同样可以实现屏幕拆分、嵌入终端组件等功能。欢迎在评论区分享你喜欢的终端拆分工具。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/5/split-terminal
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freedos.png?itok=aOBLy7Ky (4 different color terminal windows with code)
[2]: https://www.redhat.com/sysadmin/terminals-shells-consoles
[3]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[4]: https://opensource.com/sites/default/files/uploads/terminal-split-tmux2.png (tmux terminal)
[5]: https://github.com/tmux/tmux
[6]: https://opensource.com/sites/default/files/uploads/terminal-split-screen.png (GNU Screen terminal)
[7]: https://www.gnu.org/software/screen/
[8]: https://opensource.com/sites/default/files/uploads/konsole.jpg (Konsole screen)
[9]: https://konsole.kde.org
[10]: https://opensource.com/sites/default/files/uploads/emacs-rpg_0.jpg (Emacs rpg)
[11]: https://opensource.com/sites/default/files/uploads/advent-ratpoison-split_0.jpg (Ratpoison split screen)
[12]: https://opensource.com/article/19/12/ratpoison-linux-desktop
[13]: https://opensource.com/article/19/12/herbstluftwm-linux-desktop
[14]: https://gnunn1.github.io/tilix-web/