Tmux is a terminal multiplexer an alternative to GNU Screen. It means that you can begin a Tmux session and then start multiple windows inside that session. Each window keeps the whole screen and can be divided into rectangular panes.


With Tmux you can easily switch between multiple programs in one terminal, detach them and reattach them to a different terminal.
Tmux sessions are resolute, which means that programs working in Tmux will remain to run even if you become disconnected.

All commands in Tmux start with a prefix, which by default is ctrl+b.

How to install Tmux?

You can easily install Tmux using the package manager of your distro.

On Ubuntu and Debian

sudo apt install tmuxCopy


On CentOS and Fedora

sudo yum install tmuxCopy


On macOS

brew install tmux

How to start Tmux?

To begin your first Tmux session, simply type tmux in your console:

tmux

Once you are in Tmux you can see a status line at the bottom of the screen which displays information about the current session.
You can now run your first Tmux command. To get a list of all commands, you would type:

Ctrl+b ?

Generating Named Tmux Sessions

Usually, Tmux sessions are listed numerically. Named sessions are helpful if you operate multiple Tmux sessions. To create a new named session, run the tmux command like the below:

tmux new -s session_name

 

Detaching from Tmux Session

To disconnect from the Tmux session and return to the normal shell by typing:

Ctrl+b d

The program running in the Tmux session will remain to run after you detach from the session.


How to re-attach to Tmux Session?

To connect to a session first, need to get the name of the session. To get a list of the currently running sessions type as below:

tmux ls

The name of the session is the first column of the output.

0: 1 windows (created Mon Oct 08 04:53:43 2020) [158x35]
my_named_session: 1 windows (created Mon Oct 08 05:33:45 2020) [78x35]

There are two working Tmux sessions. The first one is named 0 and the second one my_named_session.
To attach to session 0, you would type:

tmux attach-session -t 0

To form a new window with shell type Ctrl+b c, the first available number from the range 0...9 will be allocated to it.

Here are some most basic commands for running Tmux windows and panes:

Ctrl+b c Create a new window (with shell)
Ctrl+b w Choose window from a list
Ctrl+b 0 Switch to window 0 (by number )
Ctrl+b , Rename the current window
Ctrl+b % Split current pane horizontally into two panes
Ctrl+b " Split current pane vertically into two panes
Ctrl+b o Go to the next pane
Ctrl+b ; Toggle between the current and previous pane
Ctrl+b x Close the current pane

 

How to customize Tmux?

When Tmux is begun, it shows its configuration parameters from ~/.tmux.conf, if the file is being.
Here is a sample ~/.tmux.conf configuration with customized status line and some added options:

# Improve colors
set -g default-terminal 'screen-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Customize the status line
set -g status-fg green
set -g status-bg black


After reading this article, you can start to use Tmux.

Esta resposta lhe foi útil? 0 Usuários acharam útil (0 Votos)