Cheat sheet for tmux

Tmux is a terminal multiplexer, or in other words, you can in a single terminal to run multiple terminal sessions, and switch between them or even place them in a single window, and to disconnect from the session, leaving it running in the background, and then go back and see the result, it can be very convenient when working via SSH. If you previously used the utility screen, then tmux is its counterpart, which has much more functions.

This article is a little cheat sheet for Tmux, which we will examine the installation, its basic capabilities and commands, as well as some of the techniques use. After reading the article you will be able to use the utility.

Install Tmux

Here everything is simple. To install the program in Ubuntu, run the following command:

sudo apt install tmux

And for installation in CentOS:

sudo yum install tmux

The syntax and options of the command Tmux

The command syntax is very simple, to create a new session, simply run the utility without parameters. To connect to the existing have to use additional options. Here is the basic syntax:

tmux command options

As for options, the most you will have to use only two – is -t (target) – which specifies the destination to which to apply the command, for example, a session ID or a connected client, and-s (session) – which is usually used to refer to the source on which to perform the action.

Command tmux to manage sessions that you can use:

  • attach-session (attach) – connect to an existing session. The parameter you need to pass the option -t and the session identifier;
  • detach-session (detach) – disconnect all clients (or passed using the-t option) from the session passed to the-s option;
  • has-session – check session is there, similarly, you need to pass the session identifier;
  • kill-server to stop any running session;
  • kill-session – terminate session passed in-t option;
  • list-clients – view clients connected to a session -t;
  • list-sessions (ls) – list of all running sessions.
  • new-session creating a new session, you can pass a session name in the-s option and the startup directory option-c;
  • rename-session – rename a session, you need to pass the session ID and a new name;

Of course, tmux is a lot more teams, but we will not consider them in this article. Basically, the teams will be used to connect to and disconnect from sessions, all other actions are performed with hotkeys and there are also sufficient.

The default to activate the shortcuts you have to press Ctrl+B, release and then press the desired key. Here are the basic keyboard shortcuts, tmux, you will need:

  • Ctrl+b c create a new window;
  • Ctrl+b w – select window from the list;
  • Ctrl+0-9 b – open the window in his room;
  • Ctrl+b , – rename current window;
  • Ctrl+b % – split current pane horizontally;
  • Ctrl+b “ – split current pane vertically;
  • Ctrl+b arrow – switch to the panel in the direction indicated by the arrow;
  • Ctrl+b Ctrl+arrow keys – resize the current pane;
  • Ctrl+b o to move to the next panel;
  • Ctrl+b – switch between current and previous bar;
  • Ctrl+b x – to close the current panel;
  • Ctrl+b [ to enter copy mode (more info below);
  • Ctrl+b ] – paste from internal clipboard to tmux;
  • Ctrl+b d – disconnect from the current session;
  • Ctrl+b : – open a command prompt.

To get started, these hot keys will be enough. Tmux cheatsheet completed, we now turn to the examples of work with the program.

How to use tmux

1. Create session

To create a new session simply run the command without any parameters:

tmux

You can also create a new session team-session and to ask her name:

tmux new-session-s losst

2. Split window panel

Window session can be divided into several panels. To be split horizontally, press Ctrl+b then release and then press Shift+”:

Similarly, you can split the panel vertically by pressing Ctrl+band then Shift+%:

The size of the active panel can be changed by clicking Ctrl+band then Ctrl and arrow:

And to switch between panels, use the keys Ctrl+b and an arrow. First, not familiar, but then conveniently.

3. Mouse support

By default, mouse support is disabled, but if you work in a graphical environment, you can enable it. This will give several benefits: you can change the active pane with the mouse, copy the text into the internal clipboard, change the size of the panels to scroll to view the output history, and so on. To do this, open the file ~/.tmux.conf and add the following lines:

vi ~/.tmux.conf

set-option-g -q mouse on
bind-key-T root WheelUpPane if-shell -F-t = "#{alternate_on}" "send-keys -M" "select-pane-t =; copy-mode-e; send-keys -M"
bind-key-T root WheelDownPane if-shell -F-t = "#{alternate_on}" "send-keys -M" "select-pane-t =; send-keys -M"

Save the changes, hit Ctrl+b :and then run the following command to restart tmux:

source ~/.tmux.conf

Configuring tmux completed, the mouse will work.

4. Copy and paste

One of the important operations when working with the terminal is the ability to copy something and somewhere to move. After enabling mouse you can just select a bunch of text with the mouse and it automatically copied to an internal buffer tmux.

If you want to be able to copy to the system clipboard before you perform actions with the mouse, hold down the Shift key:

In addition, tmux is control by copying and pasting using the keys. To switch to the copy mode press Ctrl+B [, then move the cursor to the desired location with the arrow keys. By the way, this mode can also be used to scroll. Then hit Ctrl+space to start selection, select fragment of the arrow and press Ctrl+w to copy.

To paste text from the internal clipboard by pressing the key combination Ctrl+b ]. To exit copy mode, use q or Esc.

5. Window tmux

In addition to panels in tmux you can open the Windows. This is an analogue desktop Linux. Each window is linked to a specific digit key and has its own set of panels. To create a new window hit Ctrl+b c:

The list of Windows is displayed at the bottom of the screen. To switch to the desired window and hit Ctrl+b and a window room.

6. Disconnect from session

To disconnect from a session, just press the key combination Ctrl+b d.

After disabling all running session of the program will continue to work and you will always be able to connect and see their output. This is useful when connecting via SSH, which is always in danger of rupturing.

7. The connection to the session

View the list of sessions can with the ls command:

tmux ls

And for connection, use attach:

tmux attach-t losst

You can see the list of clients connected to a session:

tmux lc

Insights

In this article we discussed the basic commands tmux, and how to use this utility. I discovered tmux not long ago. Heard about the program a long time ago, but never got around to try, and then tried it and can not without it.

Source: losst.ru

(Visited 99 times, 1 visits today)