多路复用器
Tmux with Powerline on Ubuntu – tutorial for beginners
Tmux在与会话无关的进程中运行您的窗口。这意味着如果您通过 ssh 连接到服务器、启动 tmux、执行命令并且 ssh
连接崩溃,该过程不会结束,您可以重新连接并继续在同一个会话中工作。
安装和初始配置
让我们从安装tmux和powerline开始:
sudo apt update sudo apt install tmux sudo apt install powerline -y # install the powerline fonts git clone https://github.com/powerline/fonts.git --depth=1 cd fonts ./install.sh cd .. rm -rf fonts # edit the .tmux.conf file # add the powerline status bar to tmux # edit the tmux config file and paste the below lines in it vim ~/.tmux.conf # enable the powerline status bar run-shell 'powerline-config tmux setup' # DON'T paste this line in, if you DON'T want vim keybindings # Set tmux mode to vi (default is emac) set-window-option -g mode-keys vi
一些默认的 tmux 快捷方式
tmux的默认前缀是ctrl + b
. 我们键入的大多数命令将以前缀开头,ctrl + b
然后是另一个字母或符号,在 . 之后ctrl + b
。当您看到%
它时,它会翻译成shift+5
,"
到
shift+'
等。
创建一个新会话,指定一个名称:
tmux new -s mySessionName
在会话中创建一个新窗口,将您置于窗口 1中。窗口是基于 0 索引的。注意*
终端名称旁边的 – 它表示活动窗口。
ctrl + b + c
在右侧创建窗格:
ctrl + b + %
在底部创建窗格:
ctrl + b + "
在窗格之间导航,请注意活动窗格周围有一个绿色轮廓:
ctrl + b + `left-arrow` or `right-arrow` or `top-arrow` or `bottom-arrow`
toggle focus a pane, hiding the other panes – simply press it again to
show/hide the other panes:
ctrl + b + z
move a pane to the right/left:
ctrl + b + } # move pane to right ctrl + b + { # move pane to left
change layout between panes, click it until you get the desired layout:
ctrl + b + `space`
resize a pane, you have to HOLD ctrl
while pressing the arrow keys:
#hold ctrl ctrl + b + `left-arrow` or `right-arrow` or `top-arrow` or `bottom-arrow`
close a pane, alternatively you can type exit
and press Enter
:
ctrl + d
switch to window X, in our case switch to window 0
. Notice the *
symbol
next to the active window name in the bottom bar:
# first create a new window ctrl + b + c # then switch between them ctrl + b + 0
rename a window, after pressing the key combination, delete the old window
name and type in a new one:
ctrl + b + ,
close a window, alternatively you can type exit
and press Enter
:
ctrl + d
detach a session – brings you back to your default terminal. Saves the
tmux terminal at the state from when you detached. These sessions are
preserved until the system is rebooted:
ctrl + b + d
list tmux detached sessions:
tmux ls
attach to a previously detached session – notice that 0
is the default
session name, it might be different if you rename your session. This command
brings you back to the state from when you detached the terminal:
tmux attach -t 0
rename a session – notice that 0
is the default session name for session
at index 0. **You can also tab for command-name, flag, or session name
auto-completion.
tmux rename-session -t 0 newSessionName
delete a session – alternatively you can press ctrl + d
inside an empty
session and it kill it.
tmux kill-session -t sessionName
End #
These are some of the base tmux commands. It helps you manage terminal state,
split terminal panes, create sessions inside of terminal windows.
You can detach from sessions and later on attach continuing where you left off.
Note that a system reboot will kill your sessions.
However, when you work on a server, it’s more common for your connection to the
server to be dropped for some reason (like network connectivity issues), than
for the server to completely crash and reboot.