Linux - tmux命令

0、常用参数

tmuxnew-s<name>	新建名为name的会话(无-s参数则默认以数字命名) (常用)
tmux a	恢复上一次的会话 (常用)
tmux a-t<name>	恢复(attach)名为name的会话 (常用)
tmux ls	列出所有会话 (常用)
tmux kill-session-t<name>	关闭名为name的会话 (常用)
tmux kill-server	关闭所有会话 (常用)

1、创建 tmux

在新创建的 tmux 终端运行exit命令直接退出当前 tmux 会话;返回登录的终端。

如下命令指定创建的 tmux 会话名:

tmux new -s "bgscripts"
tmux new -s "会话名称"

2、查看后台运行的 tmux 终端会话列表

运行tmux ls查看当前后台活跃的 tmux 会话

[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 21:36:45 2023) [80x24]
1: 1 windows (created Tue May  9 21:38:36 2023) [80x24]
2: 1 windows (created Tue May  9 21:38:41 2023) [80x24]
bgscripts: 1 windows (created Tue May  9 21:44:18 2023) [80x24]

3、进入指定的 tmux 会话

使用如下命令可以进入指定的 tmux 的会话

tmux attach [-t target-session]
其中 target-session 可以是 tmux 对应的编号,也可以是 tmux 对应的会话名。

使用 tmux 对应的会话编号

[root@localhost ~]# tmux attach -t 1
使用 tmux 会话名
[root@localhost ~]# tmux attach -t "bgscripts"`

4、分离会话

tmux attach到某个终端后, 可以使用ctrl+b+d或者在终端输入tmux detach分离会话。

5、会话切换

tmux attach连接到某个会话后,可以使用tmux switch [-t target-session]切换到指定的 tmux 会话。

[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 22:03:26 2023) [123x33]
1: 1 windows (created Tue May  9 22:03:31 2023) [123x33]
2: 1 windows (created Tue May  9 22:03:36 2023) [123x33]

#连接到会话2

[root@localhost ~]# tmux attach -t 2

在会话 2 终端执行tmux ls 可以看到显示当前attached的会话为 1

[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 22:03:26 2023) [123x33]
1: 1 windows (created Tue May  9 22:03:31 2023) [123x33]
2: 1 windows (created Tue May  9 22:03:36 2023) [123x33] (attached)

#切换到会话1

[root@localhost ~]# tmux switch -t 1

在会话 1 终端执行tmux ls

[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 22:03:26 2023) [123x33]
1: 1 windows (created Tue May  9 22:03:31 2023) [123x33] (attached)
2: 1 windows (created Tue May  9 22:03:36 2023) [123x33]
可以看到显示当前attached的会话为 1

6、会话重命名

命令tmux rename-session [-toldsession newsession]重命名会话名

[root@localhost ~]# tmux rename-session -t1 sess1
[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 22:03:26 2023) [123x33]
2: 1 windows (created Tue May  9 22:03:36 2023) [123x33]
sess1: 2 windows (created Tue May  9 22:03:31 2023) [123x33] (attached)
tmux 也提供ctrl+b+$重命名当前 attach 的会话

7、销毁会话

在创建会话的时候,提及可以在 tmux 会话里面直接使用exit退出会话;tmux 提供如下命令销毁会话

tmux kill-session [-a] [-t target-session]
参数-a只保留一个终端,其他全部 kill;

[root@localhost ~]# tmux ls
2: 1 windows (created Tue May  9 21:38:41 2023) [123x33]
4: 1 windows (created Tue May  9 21:56:25 2023) [123x33]
5: 1 windows (created Tue May  9 21:56:32 2023) [123x33]
[root@localhost ~]# tmux kill-session -a
[root@localhost ~]# tmux ls
5: 1 windows (created Tue May  9 21:56:32 2023) [123x33]
-t杀死指定的 session

[root@localhost ~]# tmux kill-session -t 5
[root@localhost ~]# tmux ls
failed to connect to server

tmux kill-server可以直接杀死所有会话和窗口

[root@localhost ~]# tmux ls
0: 1 windows (created Tue May  9 22:03:26 2023) [123x33]
2newsession: 2 windows (created Tue May  9 22:03:36 2023) [123x33]
sess1: 2 windows (created Tue May  9 22:03:31 2023) [123x33]
[root@localhost ~]# tmux kill-server
[root@localhost ~]# tmux ls
failed to connect to server
同样-t可以指定会话名。

7、tmux 窗口管理

tmux 创建新窗口
在当前 tmux 会话tmux new-window创建一个新的窗口;

tmux new-window [-n windowsname]创建一个名为 windowsname 的窗口

可以通过ctrl+b+number选择对应的窗口。

相关推荐

  1. Linux - tmux命令

    2024-03-13 08:46:02       41 阅读
  2. Tmux 命令使用

    2024-03-13 08:46:02       55 阅读
  3. tmux常见会话管理命令

    2024-03-13 08:46:02       54 阅读
  4. vim与tmux配置文件及常用命令总结

    2024-03-13 08:46:02       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-13 08:46:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-13 08:46:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-13 08:46:02       87 阅读
  4. Python语言-面向对象

    2024-03-13 08:46:02       96 阅读

热门阅读

  1. 反射整理学习

    2024-03-13 08:46:02       40 阅读
  2. 部署时的sql版本维护

    2024-03-13 08:46:02       44 阅读
  3. uView Collapse 折叠面板

    2024-03-13 08:46:02       53 阅读
  4. 24计算机考研调剂 | 长江大学

    2024-03-13 08:46:02       39 阅读
  5. 每天学习一个Linux命令之ifconfig

    2024-03-13 08:46:02       41 阅读
  6. 安卓kotlin面试题 101-105

    2024-03-13 08:46:02       38 阅读