tmux使用指南:1 :简介与安装

在这里插入图片描述
tmux是类Unix操作系统下的分屏终端,从使用上来说,就是可以将一个窗口分成不同的部分,在需要启动多个终端进行命令行操作的时候非常的方便。

概要信息

概要信息如下表所示:

项目 说明
官网 https://github.com/tmux/tmux/wiki
开源/闭源 开源
源码管理地址 https://github.com/tmux/tmux
License类别 ISC License
开发语言 C
当前稳定版本 2.9a(2019/5/1)
操作系统支持 类Unix操作系统

最主要的功能特性就是可以更为方便地进行终端的分屏,如下图示例:
在这里插入图片描述

对于那些需要起多个终端进行操作的场景,尤其是一边操作一边需要监控实施信息,或者开发时需要同时操作前端、后端、数据库、实时运行的状态时,可以很好的提高效率。tmux从2009/9/22开始的初始版本至今也已经有10年了,而终端的分屏工具则有很长的历史,则可以溯源到30年前的GNU Screen,至今仍在更新
在这里插入图片描述

功能特性

tmux包含大部分GNU Screen的特性,最大的特性就是用户不需要在各个终端或者一个终端的多个tab之间跳来跳去,主要特性包括:

  • 支持分屏功能,支持同时处理多个操作
  • 支持快速便捷的操作切换
  • 可以使用vi或者Emacs方式进行管理
  • 支持缓冲区管理,更方便复制粘贴操作
  • 配置更加容易,支持定制化配置
  • 支持横向和纵向分屏方式
  • 完善的快捷键支持以及自定义

安装

方式1: 使用操作系统包管理工具

可以使用源码编译或者操作系统所提供的包来安装,以macOS为例,可以直接使用brew来进行安装:

macOS安装命令:brew install tmux

CentOS安装命令:yum install tmux

macOS上执行brew的部分主要安装示例日志如下所示(注意需要使用到libevent):

liumiaocn:homebrew-core liumiao$ brew install tmux
==> Installing dependencies for tmux: openssl@1.1, libevent and ncurses
==> Installing tmux dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/10/104ef018b7bb8fcc49f57e5a60359a28a02d480d85a959e6141394b0571cbb28?__gda__=exp=15731055
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs
..省略
==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing tmux dependency: libevent
==> Downloading https://homebrew.bintray.com/bottles/libevent-2.1.11_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/1e/1e14fc34baae0b65cac6d7c75bc5ed0ccb1f6bbaa30c8f0f8477ab8ba85fb3c5?__gda__=exp=15731055
######################################################################## 100.0%
==> Pouring libevent-2.1.11_1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/libevent/2.1.11_1: 1,063 files, 5MB
==> Installing tmux dependency: ncurses
==> Downloading https://homebrew.bintray.com/bottles/ncurses-6.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/01/01e031f6bb1513edcb26d78a15dc5e85969c42e9dc40ae3cbc3535982658abc0?__gda__=exp=15731055
######################################################################## 100.0%
==> Pouring ncurses-6.1.mojave.bottle.tar.gz
==> Caveats
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
..省略
==> Summary
🍺  /usr/local/Cellar/ncurses/6.1: 3,869 files, 8.3MB
==> Installing tmux
==> Downloading https://homebrew.bintray.com/bottles/tmux-2.9a_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/a6/a6c847ffc57c9e6d730b1dcfb3ca193588cfdb679a60f221a41690ac8ec202a7?__gda__=exp=15731055
######################################################################## 100.0%
==> Pouring tmux-2.9a_1.mojave.bottle.tar.gz
==> Caveats
Example configuration has been installed to:
  /usr/local/opt/tmux/share/tmux

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/tmux/2.9a_1: 10 files, 748.5KB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs
..省略
==> ncurses
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
..省略
==> tmux
Example configuration has been installed to:
  /usr/local/opt/tmux/share/tmux
  
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
liumiaocn:homebrew-core liumiao$ 

方式2: 源码编译安装

也可以直接下载源码,编译安装也非常方便,以macOS为例,进行如下步骤即可。

步骤1: 下载源码至本地

liumiaocn:~ liumiao$ git clone https://github.com/tmux/tmux
Cloning into 'tmux'...
remote: Enumerating objects: 38287, done.
remote: Total 38287 (delta 0), reused 0 (delta 0), pack-reused 38287
Receiving objects: 100% (38287/38287), 10.43 MiB | 454.00 KiB/s, done.
Resolving deltas: 100% (29728/29728), done.
liumiaocn:~ liumiao$

步骤2: 编译准备

C语言编译的执行autogen.sh,提示如下错误信息

liumiaocn:~ liumiao$ cd tmux
liumiaocn:tmux liumiao$ ls *.sh
autogen.sh
liumiaocn:tmux liumiao$ sh autogen.sh 
autogen.sh: line 15: aclocal: command not found
aclocal failed
liumiaocn:tmux liumiao$

这是因为没有安装autoconf的原因,使用brew install autoconf即可解决问题。

liumiaocn:tmux liumiao$ which autoconf
/usr/local/bin/autoconf
liumiaocn:tmux liumiao$ autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.
liumiaocn:tmux liumiao$ sh autogen.sh 
configure.ac:25: installing 'etc/compile'
configure.ac:10: installing 'etc/config.guess'
configure.ac:10: installing 'etc/config.sub'
configure.ac:8: installing 'etc/install-sh'
configure.ac:8: installing 'etc/missing'
Makefile.am: installing 'etc/depcomp'
configure.ac: installing 'etc/ylwrap'
liumiaocn:tmux liumiao$ 

步骤3: 编译

使用./configure 和 make即可完成编译,首先执行configure完成编译配置。

liumiaocn:tmux liumiao$ ./configure 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... etc/install-sh -c -d
...省略
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
liumiaocn:tmux liumiao$ 

tmux和Chomium等都是基于libevent的应用,所以如果本地没有安装的话,由于在编译的时候会用到其头文件和链接库,会提示错误,在macOS下使用brew install libevent即可,如果和其他有冲突的话,直接从http://libevent.org/下载源码编译会更快捷。生成二进制文件直接执行make即可使用configure所生成的Makefile进行编译了,执行日志如下所示:

liumiaocn:tmux liumiao$ make
depbase=`echo alerts.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
	gcc -DPACKAGE_NAME=\"tmux\" -DPACKAGE_TARNAME=\"tmux\
...省略
-L/usr/local/Cellar/libevent/2.1.11_1/lib -levent  -lncurses -lresolv
liumiaocn:tmux liumiao$ 

确认所生成的tmux二进制文件的版本:

liumiaocn:tmux liumiao$ ls tmux
tmux
liumiaocn:tmux liumiao$ ./tmux -V
tmux next-3.1
liumiaocn:tmux liumiao$ 

然后就可以快速使用tmux了,比如这里将当前窗口拆为4部分,分别用于显示top结果,确认man tmux的信息、确认操作系统的信息、执行当前操作等就可以在一个窗口进行了。
在这里插入图片描述

发布了920 篇原创文章 · 获赞 1260 · 访问量 389万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览