痛点
本机连接远程进行开发或实验,但经常要跑一个很久的程序,比如炼丹的训练或者sftp传输大文件
之前的做法使用nohup和&开启后台进程,但总是会报各种各样奇怪的问题
最后通过别人的推荐接触到tmux和screen这种窗口管理类的指令
安装
sudo apt install tmux
cd ~/
touch .tmux.conf
tmux source ~/.tmux.conf
默认的前缀prefix:Ctrl + B
,后面的所有指令都要先按这个
常用指令
启动tmux session
tmux new -s mywindow
session中的window
- 在session内新建一个窗口:
prefix + c
- 在窗口内切换:
prefix + 0
通过数字切换,*
代表当前活跃的窗口 - 关闭当前窗口:
prefix + x
退出session
窗口内远程运行的指令不会退出
prefix + d
恢复session
tmux ls
tmux attach -t mytest
tmux a -t mytest
关闭session
tmux kill-session -t mytest
查看历史输出
如果直接滑动鼠标向上会发现看不了之前的输出,这是因为tmux接管了正常的console
prefix + [
进入查看模式,q
可退出,PgDn PgUp
进行翻页
安装插件
在.tmux.conf
添加
set -g @plugin "arcticicestudio/nord-tmux"
set -g @plugin 'tmux-plugins/tmux-pain-control'
run '~/.tmux/plugins/tpm/tpm'
然后在tmux里Ctrl+I
即可安装插件,安装完会在~/.tmux/plugins
或者直接下载相关仓库到本地,例如**~/.tmux/themes/nord-tmux
地址**
然后在.tmux.conf
结尾添加**run-shell "~/.tmux/themes/nord-tmux/nord.tmux"
**
最后**tmux source-file ~/.tmux.conf
**
Resources
- http://c.biancheng.net/linux/tmux.html
- https://zhuanlan.zhihu.com/p/386085431
- https://www.nordtheme.com/docs/ports/tmux/installation
- https://github.com/tmux-plugins/tmux-pain-control