TMUX, a better way to manage terminals

Recently i discovered tmux by watching a youtube video of Bryan Lunduke.

What is TMUX ?

tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

From the tmux man-page:

NAME
"tmux _ terminal multiplexer

SYNOPSIS
tmux [-28lCquvV] [-c shell-command] [-f file] [-L socket-name] [-S socket-path] [command [flags]]

DESCRIPTION
tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

When tmux is started it creates a new session with a single window and displays it on screen. A status line at the bottom of the screen shows information on the current session and is used to enter interactive commands.

A session is a single collection of pseudo terminals under the management of tmux. Each session has one or more windows linked to it. A window occupies the entire screen and may be split into rectangular panes, each of which
is a separate pseudo terminal (the pty(4) manual page documents the technical details of pseudo terminals). Any number of tmux instances may connect to the same session, and any number of windows may be present in the same
session. Once all sessions are killed, tmux exits."

The main thing to understand, it provides the user with a lot more panes to look at the server(s). The options are staggering, so i keep it brief.

Starting tmux
Installing the package with your favourite package-manager, entering ‘tmux’ on your shell.
Nothing fancy happening here, just a black screen with a green bar at the bottom.

Tmux command prefix
tmux uses a command prefix (Ctrl-b) to access functions and a tmux command (:) prompt not unlike what vi(m) is using.

Create a new window
Create a new window with a shell with ‘Crtl-b c‘. That is : press ‘Ctrl’ and ‘b’ together, let go and press ‘c’. You can repeat this for more windows.

Split windows
To split a window, my two favourites are to split left-right (Ctrl-b “) and split top-bottom (Ctrl-c %). Especially when i write code or ansible playbooks, i like to have a section of the window with the file(s) open in vim, another section to execute the playbook and perhaps a 3th section for documentation like ansibe-doc.

Navigating the sessions
To navigate use (Ctrl-b [arrow-up]/[arrow-down]/[arrow-left][arrow-right]). This takes some getting used to because when you enter this mode, for a certain period the arrow-keys will move your cursor to the different sessions in your window.

Detach and Attach
Another nice feature is the option to detach (Ctrl-b d) and re-attach (tmux attach) to a session. This is useful for when you work from different devices on the same server. By detaching your tmux session and locking your console, you can simply re-attach and get your formatted console back.

Wrap up
So to wrap up, the commands/functions i use on a day to day bases:

Key-strokesFunction
Ctrl-b ccreate new window with sessions
Ctrl-b ddetach current session (keeps running in background)
Ctrl-b wshow list of windows to select
Ctrl-b zresize window (full-screen)
Ctrl-b [up]cursor up (pane up)
Ctrl-b [down]cursor down (pane down)
Ctrl-b [left]cursor left (pane left)
Ctrl-b [right]cursor right (pane right)

More information

https://en.wikipedia.org/wiki/Tmux

Rik has written 7 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>