Recently, when using an open source tool, I found a tool called tmux. Then I found that Tmux is quite popular, the repo star has 20K+, and my commonly used iTerm2 is also integrated with tmux. Based on this, it is necessary to understand tmux and clarify the usage scenarios.

Since the current use is still shallow, please point out if any mistakes

Concept

Start with the concept and understand its function.

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

  1. Personal understanding is that tmux saves the terminal session on-site. For example, SSH is connected to a VPS, vi edits a file, directly closes the session, and then reopens the connection, you will find that the state is lost, you need to re-enter the target path and reopen it edit. With tmux, you can save this session, re-access the target machine, load the previously saved session, and everything will be restored as before.
  2. The reason why tmux can save sessions is because after tmux is installed on the target server, a separate service will be started for on-site saving.

Tmux Installation

Understand the above principles, you can understand that tmux is not necessarily installed locally, but installed on the machine that needs to save the session.

The installation commands in common operating system environments are as follows

# macOS
brew install tmux

# centos
yum install tmux

iTerm2 Config

After Tmux is installed, followed by the settings of the local terminal App

  1. Global tmux settings

The picture shows my current settings, basically keep the default settings.

  1. Individual profile configuration startup command
  2. For the machine where tmux needs to be enabled, the command configuration is as follows.
  • # Connect to the target machine, then execute the tmux session load, if not, open a new session ssh -p 22 -t root@123.160.122.79 "tmux -CC attach || tmux -CC"

It can be used after setting as above.

Write at the End

  1. Searching for information, you will find that tmux is very rich in configuration and can be very complicated to use, which invisibly increases the mental burden, but you don’t need to worry about it.
  2. In the case of using iTerm2, operations such as split screen and session opening are already available. iTerm2 itself has mapped many functions of tmux, so it is enough to maintain the operating habits of iTerm2. After in-depth use, if there are still insufficient Fill in the gaps.

References

--

--

--

Develop with pleasure!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Install Osclass on IBM Cloud

Micro-services architecture for fault tolerant, highly scale-able software

FHIR Startup Guide

AsgardCMS Install Guide

Recasting Financial Services in the Era of Web 3.0

Please Welcome Flutter 3.0!

How I Plan to Get 100 Followers by the End of the Year

Foreign function interface: Calling C functions from Deno

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alan He

Alan He

Develop with pleasure!

More from Medium

Which macOS terminal should you use?

The Best Application for Command Line To-Do List Management

Customise your zsh terminal and prompt in MacOS!

How to view or recover the WiFi password on your Mac