Tmux使用

创建新会话

tmux new -s Test

查看会话

tmux list-sessions

连接已有会话

tmux attach -t Test

tmux attach -t Test -r   #只读模式

断开会话

Ctrl + b, d

会话中的窗口操作

前缀按键,默认为Ctrl + b,以下命令,先按前缀键后再执行

命令功能
c创建新窗口
,重命名当前窗口
0-9切换窗口(下面有窗口编号,当前窗口后面有* )
( / p切换到前一个窗口
) / n切换到后一个窗口
d分离当前客户端
L切换会话
i显示当前窗口信息
%垂直分割窗口
"水平分割窗口
方向键切换窗格
空格调整窗格排列方式
{/}交换窗格
Ctrl + 方向键调整窗口分割线
x关闭当前窗格
z最大化当前窗格(窗口名称后会添加*Z)
t显示时间

Tmux插件

Oh My Tmux!

Pretty & versatile tmux configuration made with ❤️ (imho the best tmux configuration that just works)
Github:https://github.com/gpakosz/.tmux

默认没有~/.tmux.conf文件,Oh My Tmux是一套优化好的tmux配置。

  • 安装
    Requirements:
    tmux >= 2.1 running inside Linux, Mac, OpenBSD, Cygwin or WSL (Bash on Ubuntu on Windows)
    outside of tmux, $TERM must be set to xterm-256color
    To install, run the following from your terminal: (you may want to backup your existing ~/.tmux.conf first)
cd ~
git clone https://github.com/gpakosz/.tmux.git
ln -s -f .tmux/.tmux.conf
cp .tmux/.tmux.conf.local .

tmux-plugin-manager

Github:https://github.com/tmux-plugins/tpm
使用apt安装

apt install tmux-plugin-manager

安装路径为/usr/share/tmux-plugin-manager

使用apt或克隆源码后,编辑~/.tmux.conf文件,添加以下几行内容:

#List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

#Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

#Initialize TMUX plugin manager (添加到.tmux.conf文件最后一行)
run -b 'usr/share/tmux-plugin-manager/tpm'

tmux-logging

Github:https://github.com/tmux-plugins/tmux-logging

  • 使用TPM安装 (推荐该方式)
    编辑~/.tmux.conf文件,增加一行:
set -g @plugin '/tmux-plugins/tmux-logging'

然后进入Tmux,按prefix + I 刷新插件,tpm会自动下载该插件。

  • 使用:
  1. 记录日志
    Toggle (start/stop) logging in the current pane.
    快捷键:prefix + shift + p
    File name format: tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
    File path: $HOME (user home dir)
    Example file: ~/tmux-my-session-0-1-20140527T165614.log

  2. 截屏
    Save visible text, in the current pane. Equivalent of a “textual screenshot”.
    快捷键:prefix + alt + p
    日志文件名格式: tmux-screen-capture-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
    文件保存路径: $HOME (user home dir)

NOTE: this functionality depends on the value of history-limit - the number of lines Tmux keeps in the scrollback buffer. Only what Tmux kept will also be saved, to a file.
Use set -g history-limit 50000 in .tmux.conf, with modern computers it is ok to set this option to a high number.

  1. 清除pane历史记录
    快捷键:prefix + alt + c

修改日志条数

#increase history size
set -g history-limit 10000

搜索、选择、复制

Ctrl-b + [,进入选择模式,可以设置VI的搜索快捷键进行搜索,按空格开始选择,按回车确认选择内容
Ctrl-b + ], 粘贴选择的内容

使用VI搜索快捷键

编辑~/.tmux.conf,添加一行内容:

# Use vim keybindings in copy mode
setw -g mode-keys vi

复制内容到系统剪贴板

# -- clipboard -----------------------------------------------------------------

# in copy mode, copying selection also copies to the OS clipboard
#   - true
#   - false (default)
# on macOS, this requires installing reattach-to-user-namespace, see README.md
# on Linux, this requires xsel or xclip

tmux_conf_copy_to_os_clipboard=true

支持鼠标模式

# start with mouse mode enabled
set -g mouse on

Xshell中,开启鼠标模式后,按住Shift点击邮件,调出Xshell的右键菜单。

配置文件

.tmux.conf

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是 tmux使用文档。 # 什么是 Tmux Tmux 是一个终端复用工具,它可以让你在单个终端窗口中同时运行多个终端会话,并且可以在不同的会话之间切换。 # 安装 TmuxLinux 上安装 Tmux 可以使用以下命令: ```shell sudo apt-get install tmux # Debian/Ubuntu sudo yum install tmux # CentOS/RHEL ``` # Tmux 基础用法 ## 启动 Tmux 启动 Tmux 可以使用以下命令: ```shell tmux ``` ## Tmux 快捷键 Tmux 的所有操作都是通过快捷键来完成的。下面是一些常用的快捷键: - `Ctrl-b ?` 显示快捷键帮助 - `Ctrl-b c` 创建一个新窗口 - `Ctrl-b n` 切换到下一个窗口 - `Ctrl-b p` 切换到上一个窗口 - `Ctrl-b d` 断开当前会话 - `Ctrl-b [0-9]` 切换到指定编号的窗口 - `Ctrl-b "` 水平分割当前窗口 - `Ctrl-b %` 垂直分割当前窗口 ## Tmux 窗口和面板 Tmux 中的窗口和面板类似于屏幕上的分隔符,您可以使用它们将屏幕分成多个区域。 ### 窗口 Tmux 中的窗口是您可以在其中运行应用程序的虚拟终端。默认情况下,Tmux 启动一个窗口,但您可以创建多个窗口。 创建新窗口:`Ctrl-b c` 切换到下一个窗口:`Ctrl-b n` 切换到上一个窗口:`Ctrl-b p` 切换到指定编号的窗口:`Ctrl-b [0-9]` ### 面板 Tmux 中的面板类似于窗口,但它们是窗口的子区域。您可以在面板中运行应用程序,就像在窗口中一样。 水平分割当前窗口:`Ctrl-b "` 垂直分割当前窗口:`Ctrl-b %` 切换到下一个面板:`Ctrl-b o` 在面板之间移动:`Ctrl-b 方向键` 关闭当前面板:`Ctrl-b x` ### Tmux 命令 Tmux 的命令可以通过 `Ctrl-b :` 来输入。 例如: - 保存当前 Tmux 会话:`Ctrl-b :save-buffer /path/to/file` - 加载之前保存的 Tmux 会话:`Ctrl-b :source-file /path/to/file` # 总结 Tmux 可以让你在一个终端窗口中同时运行多个终端会话,这在日常工作中非常有用。掌握 Tmux 的基本用法对于 Linux 用户来说是非常重要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值