研发效能 命令行神器 Tmux

花菜 · 2022年05月20日 · 3394 次阅读

About Tmux

tmux is a program which runs in a terminal and allows multiple other terminal programs to be run inside it. Each program inside tmux gets its own terminal managed by tmux, which can be accessed from the single terminal where tmux is running - this called multiplexing and tmux is a terminal multiplexer.
翻译一下
Tmux 是一个运行在终端上并允许多个其他终端程序在其中运行的程序。tmux 内部的每个程序都有由 tmux 管理的自己的终端,可以从 tmux 运行的单个终端访问终端——这称为多路复用,tmux 是一个终端多路复用器。

翻译完其实也没看懂_^
对于 tmux,我个人理解就是:
保持 ssh 连接的状态,即使网络不好,又或者不小心关闭了窗口。
下次进来还是能够保持原来状态, 不用担心 ssh 重连后,当前进程挂掉,编辑的东西没保存好
听起来还是有点抽象,看个图就明白了。
image-20220520154134325

左下角的状态说明:
s1 指当前的会话名称,可以自定义
win1*,其中 win1 指 window 名称是 win1(可以自定义),* 指当前窗口是在 win1,0 代表 win1 的位置是第 0 个,可以通过快捷键C-b 0,也就是 Ctrl + b,再按一下 0,就可以切换到这个窗口
win1 这个 window 有 3 个 pane,可以 win1 是一个窗口,包含了 3 个窗格

Install Tmux

yum install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y tmux2u

mac

brew install tmux

Session

new session

local

# new a tmux session, name s1
tmux new -s s1

sever

# s1 is session name
# attach it when exists
# else new it
ssh -t your_server_ip "tmux attach -t s1 || tmux  new -s s1"

list session

tmux ls

attach session

tmux attach -t s1

rename session C-b $

Window

new window C-b c

close window C-b &

rename window C-b ,

switch window C-b w

select window C-b 1 select to window that index is 1

split-window

  • horizontally C-b %
  • vertically C-b "

Pane

kill a pane C-b x

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册