参考链接:https://linuxize.com/post/getting-started-with-tmux/https://linuxize.com/post/getting-started-with-tmux/
不知道大家有没有使用过‘screen’,如果你使用过,那么你也会喜欢Tmux,两种类似的功能。
使用Tmux有个最大的好处是它的会话是持久的,即使你被断开连接,在Tmux中运行的程序将继续运行。
1. 安装Tmux在ubuntu和Debian上安装Tmux:
sudo apt install tmux
在Centos和Fedora上安装Tmux:
sudo yum install tmux
在macOS上安装Tmux:
brew install tmux2. 创建一个新的会话。
tmux
默认情况下,Tmux会话是以数字命名的。当你运行多个Tmux会话时,命名的会话很有用。要创建一个新的命名的会话,请用以下参数运行tmux命令。
tmux new -s session_name3. 脱离Tmux会话
运行的程序在你脱离该会话后将继续运行(或者exit也可)。
Ctrl+b d4. 重新连接到Tmux会话
在恢复到一个会话前,你需要找到该会话的名称。获得当前正在运行的会话的列表,请使用:
tmux ls
会话的名称是输出的第一列。
0: 1 windows (created Sat Sep 15 09:38:43 2018) [158x35] my_named_session: 1 windows (created Sat Sep 15 10:13:11 2018) [78x35]
从输出看,有两个正在运行的Tmux会话。第一个名为0,第二个是my_named_session,如果你要附加到会话0,你可以键入
tmux attach-session -t 05. 如何使用Tmux窗口和面板
下面是一些管理Tmux窗口和窗格的最常用的命令:
Ctrl+b c Create a new window (with shell) Ctrl+b w Choose window from a list Ctrl+b 0 Switch to window 0 (by number ) Ctrl+b , Rename the current window Ctrl+b % Split current pane horizontally into two panes Ctrl+b " Split current pane vertically into two panes Ctrl+b o Go to the next pane Ctrl+b ; Toggle between the current and previous pane Ctrl+b x Close the current pane
6. 定制Tmux
当Tmux启动时,它从~/.tmux.conf中读取其配置参数。下面是一个 ~/.tmux.conf 配置样本,其中包括自定义的状态行和一些附加选项。
# Improve colors set -g default-terminal 'screen-256color' # Set scrollback buffer to 10000 set -g history-limit 10000 # Customize the status line set -g status-fg green set -g status-bg black



