A basic guide to Tmux
In this entry, I will create a basic guide to Tmux. The topics covered will include: What is Tmux? Why might it be useful for you? And its basic commands.
¿What is Tmux?
Tmux is a terminal multiplexer that allows us to switch between multiple programs in the terminal and also lets us access them again from another terminal.
¿Why use Tmux?
If you’re on Windows, this might not seem very interesting, really. Windows is known for its graphical interface, which makes common tasks easier for users. But when it comes to servers, things change.
Linux plays a significant role in the server world, and you won’t always have access to Linux’s GUI because it comes with additional costs. With that cost, a company could instead allocate more space, memory, etc.
Therefore, on a large number of servers, only the console is used, and this is where Tmux becomes relevant.
A simple terminal is not the same as one that can be split into windows, panes, and has additional advantages.
Basic Comands Tmux
In this section, we will look at the most basic commands—those that will keep you using Tmux without getting stuck when you’re on a client’s server or your own server.
Console / Terminal
These are the commands you will use in the console to start Tmux or resume windows from a previous terminal session.
To create a new session, you can type:
tmux new
Resume what you had open in the previous terminal.
tmux a
You can list the sessions at any time with:
tmux ls
We can also name the session when we create it.
tmux new -s nombre_sesion
This way, we can use it:
tmux attach -t nombre_sesion
Inside tmux
At any time, you can use Ctrl + b
followed by ?
. If you don’t remember a command, Ctrl + b
followed by ?
will show you a list with a brief description of the commands.
You can exit the session with the following command:
convinación | descripción |
---|---|
ctrl + b d | exit session |
Windows
Let’s look at the commands for windows. With these commands, you can create a window, delete one, or select a specific window.
convinación | descripción |
---|---|
ctrl + b c | creates a new window |
ctrl + b & | ask to delete actual window |
ctrl + b a number in the array | select the window based on the array number |
Panels
Commands for panes: Panes can be especially useful when you’re configuring servers, so keep them in mind.
convinación | descripción |
---|---|
Panel Creation | |
ctrl + b % | divide the panel with a vertical line |
ctrl + b " | divide the panel with a horizontal line |
Panel adjustment | |
maintaining presed ctrl + b ← | Increase the size of the panel to the Left |
maintaining presed ctrl + b → | Increase the size of the panel to the right |
maintaining presed ctrl + b ↑ | Expand the panel upwards. |
maintaining presed ctrl + b ↓ | Expand the panel downwards |
Panel change | |
without maintaining ctrl + b ← | Move to the panel on the left. |
without maintaining ctrl + b → | Move to the panel on the right |
without maintaining ctrl + b ↑ | Move to the panel that is at the top |
without maintaining ctrl + b ↓ | Move to the panel that is at the bottom |
Line command mode
Line commands: Line commands are especially used to delete a panel or all the panels.
convinación | descripción |
---|---|
ctrl + b : | habilita la linea de comandos |
In the command line, we can use the following commands:
To delete all the panes:
:kill-pane -a
To delete the panel you’re currently in:
:kill-pane
Delete a session: This will remove everything associated with the session, including windows and panes.
:kill-session
Copy and paste
We also have commands for copying and pasting, but personally, I prefer using the mouse—select what I want and then middle-click where I want to paste what I’ve selected.
Basically, these are the commands, which you can see in a response on Unix StackExchange.
- Ctrl+b, [ Enter copy(?) mode.
- Move to start/end of text to highlight.
- Ctrl+Space
Start highlighting text (on Arch Linux). When I’ve compiled tmux from source on OSX and other Linux’s, just Space on its own usually works. Selected text changes the colours, so you’ll know if the command worked.
- Move to opposite end of text to copy.
- Alt+w Copies selected text into
tmux
clipboard.
On Mac, use Esc+w. Try Enter if none of the above work. - Move cursor to opposite tmux pane, or completely different tmux window. Put the cursor where you want to paste the text you just copied.
- Ctrl+b, ] Paste copied text from tmux clipboard.