Tmux it is a piece of software that runs on the terminal. It is short for Terminal Multiplexer. It can create terminal sessions that keeps running even when you log off the system, and when you log in again you can hook into the same session and continue working. Use cases for this include -but are not limited to-:
There's no doubt that it's a useful tool, but it can be unintuitive to use. That's why we include the most important commands in this guide needed to get you started.
tmux is already installed on all our machines. In case you want to install it on your machine too, the installation is straight forward on major operating systems.
sudo apt install tmux
brew install tmux
since Windows 10, there has been an ubuntu subsystem included that can be used and tmux can be installed with running the linux command in the ubuntu terminal.
Let's first check if any tmux sessions are running
Next, we create a tmux session called
tmux new -s TmuxSession
Then tmux will open a new terminal session where we can run any command we want, for the purposes of this guide, we detach temporarily from the session to return to our old terminal window with using the keys
<ctrl-b> + d
tmux uses the concept of a
bind-key. It is a combination of keys pressed together to tell tmux to listen to keyboard input as commands, in the previous command we used the default
bind-key which is the control button + the letter b. This tells tmux to check the following input for commands. The next letter we typed is
d which tells tmux to
detach from the current session. There are many other commands that can be found in the extra resources section.
A very useful command to see if others are logged in the system is
this also works with tmux and it shows if anyone else is running a tmux session on the same machine.
If we run this command we will see that the terminal session
TmuxSession is still running. In order to open it again, or more accurately, to
attach to it again we run
tmux a -t TmuxSession
we can then exit this session as we would exit any normal terminal session, by running
now if we run
tmux ls again we confirm this by seeing that no sessions are live.
This is a list of the most common tmux commands you will need when starting out. It includes all commands mentioned in the previous trial run and some other useful commands. You can find a more comprehensive list in the extra resources section.
start new without session name (it will assign a number instead to the session name):
start new with session name:
tmux new -s myname
tmux a # (or at, or attach)
attach to named:
tmux a -t myname
tmux kill-session -t myname
once inside a session, you can detach from it with:
<ctrl-b> + d
tmux allows for a session(s) to be shared with multiple users. This is achieved by specifying a socket (which is just a file) that both users have access to.
Here's a trial run for some for two users userA and userB.
Assuming userA runs this command:
tmux -S /tmp/shareds new -s shared
the first argument passed in this command is an example socket, the rest of the arguments are as before. So this creates a new shared session called
Then for userB to attach to the same session he would have to run:
tmux -S /tmp/shareds a -t shared
More info can be found in the extra resources section.