tmux is a useful way to maintain working states on remote servers. I use it at work a lot when I have a long running process that I want to come back to later. It allows me to detach and re-attach whenever I want. It’s similar to screen
but in my opinion, it’s better.
I’ve assumed that tmux is available for you to run - ask your sys admin!
Again, I’ve assumed you’re running a long-running process on a remote server and that the remote server has tmux on it. Connect to the remote server and type tmux
.
By doing that, you have just created your first tmux session that you can disconnect from and come back to later.
[user@server ~]$ tmux
One benefit of tmux is that you can run multiple sessions at the same time. If you’re doing that, you’ll need a way to see what sessions are available, so use the ls
argument.
[user@server ~]$ tmux ls
The output will be something similar to:
0: 1 windows (created Wed Dec 6 22:06:27 2017) [63x13] (attached)
By default, your new session will be given a number to identify it but you can give a session a name if you want to.
You can create a new session with a name of your choice by using the -s
argument and supplying a name for the session.
[user@server ~]$ tmux new -s my-long-running-process
To connect to a session, you can type tmux a
and it’ll connect you to the first available session.
[user@server ~]$ tmux a
Or if you have given your session a name, you can attach to it using the name.
[user@server ~]$ tmux a -t my-long-running-process
You can detach from an existing session by typing detach
. This means that you can shut your terminal window and come back to that session later.
[user@server ~]$ tmux detach