tmux使用教程
tmux 基本概念
tmux 是一个终端复用器。平时在终端中运行的程序,如果我们把终端关闭了,那么运行的程序就断开了,比如我们 ssh 连接远程服务器,如果 ssh 连接中断了,那么我们跑的程序也就断了。tmux 就能解决这个痛点。除此以外 tmux 还能用于终端分屏之类的功能。
首先介绍 tmux 中的基本概念,会话(session),窗口(windwos),窗格(pane)。会话是于操作系统的一次交互,每个会话可以有多个窗口(类似于浏览器的标签页),每个窗口可以有多个窗格(类似于当前分屏)
Getting Started - tmux/tmux Wiki 中提到
In summary:
- Programs run in terminals in panes, which each belong to one window.
- Each window has a name and one active pane.
- Windows are linked to one or more sessions.
- Each session has a list of windows, each with an index.
- One of the windows in a session is the current window.
- Sessions are attached to one or more clients, or are detached (attached to no clients).
- Each client is attached to one session.
前缀键:当我们进入 tmux 中后,有大量快捷键,使用方式是,先按前缀键,然后再按对应的某个键,比如在 tmux 中查看帮助的使用方法为,先使用前缀键 ctrl+b,然后按 ?。后文中我们把前缀键简写为 prefix,比如获取帮助的快捷键,我会在后文中写作 prefix ?,默认的 prefix 是 ctrl + B
tmux 基本使用
首先输入 tmux 相当于开启了一个会话(新建一个无名称的会话),然后会话中会默认新建一个窗口
session
命令 | 操作 | 快捷键 |
---|---|---|
tmux new -s <name> |
创建会话 | |
tmux detach |
断开会话,后台运行 | prefix d |
tmux ls |
查看所有会话 | |
tmus a -t <name> |
进入某个会话 | |
tmux switch -t <name> |
切换到某个对话 | prefix s |
tmux kill-session -t <name> |
关闭某个会话 | |
|
重命名会话 | prefix $ |
上述指令中,a 指 attach,t 指 target,s 指 session
window
命令 | 操作 | 快捷键 |
---|---|---|
|
创建窗口 | prefix c |
|
切换窗口 | prefix 数字 |
|
重命名窗口 | prefix , |
pane
命令 | 操作 | 快捷键 |
---|---|---|
|
当前 pane 左右一分为二 | prefix % |
|
当前 pane 上下一分为二 | prefix " |
|
移动光标切换 pane | prefix 方向键 |
推荐阅读
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ruoy's Blog!
评论