However, with a program such as tmux, this overhead of developer energy and time is removed completely. Furthermore, with tmux, you can not only work with multiple machines and multiple environments at the same time, but you can also quickly switch between them. Therefore, learning how to better handle tmux sessions can potentially boosting your productivity and your ability to work.
To show a list of all the tmux sessions currently running on a machine, the command tmux ls is used in the terminal, as shown below:
Information given by tmux ls command appears in the following order:
If a machine does not have any tmux sessions running when you run tmux ls command, the following output is shown:
Like many other operations for tmux, renaming a session in tmux can be done in one of two ways. The first way to rename a session in tmux is to do it from outside of the session, in the terminal. Use the following command to rename a session:
For example, in the screenshot below, a tmux session is currently running, called webdev, which we want to rename as website1.
If the renaming operation is successful, the command does not produce anything, and we can check the new name of the session through $ tmux ls as shown:
The second way to rename a tmux session is from within the session. Similar to the example above, we are going to rename the following session from webdev to website1:
The key combination Prefix, $ is used to achieve that. For example, in my Ubuntu installation, this key combination would be Ctrl + b, $.
The result is shown in the screenshot. As you can see, the session is now named website1 in the bottom left corner of tmux:
Similarly, if you need to create a tmux session with a name beforehand, instead of renaming it later, you can use the following syntax for tmux new command:
For example, if you want to create another session where you are setting up another remote server for VPN use, you can create a tmux session called vpnserver by using the following command:
This new tmux session is shown below:
When you want to attach your terminal to a currently running tmux session, the command to use is:
For example, if you want to continue your work on the website1 session and currently your terminal is not attached to that specific tmux session, you run the following command:
To get a list of sessions you can attach to, use the ls command as shown in a section above.
Detaching from tmux requires using the command Prefix + d. For example, in my Ubuntu installation, the prefix command is Ctrl + b, so to detach from the currently running session, I need to press Ctrl + b and then press d to detach. Once you’ve detached your terminal from the tmux session, the session is still running. This means that any processes you’ve left running in the session, such as htop, a file download through curl, or any batch command, will continue to run until completed.
This function of tmux works well for remote servers where you need to ssh to initiate a process and then let it run in the background. Unlike directly running commanding from your terminal through ssh, using tmux allows you to use detach command to run any process in the background.
Killing a tmux session destroys it completely. Therefore, this command should be used with care. This command is not reversible and can lead to a loss of work.
Similar to renaming a tmux session, there are two ways to kill an individual session. The first way is through the terminal, and the second is from within the tmux session.
In order to kill a tmux session from the terminal, use the following command:
For example, if I have a tmux session running called vpnserver and I want to kill it through the terminal, I can use the following command:
As shown below, the session is no longer available and is destroyed.
The second way of killing a tmux session is from within the session. Simply exit out of all the panes and windows running in that session and exit out of the last window of the session. This will cause the session to be killed, just as it would have been through the terminal. The screenshot below shows a running session of tmux called vpnserver:
When we attach our terminal to this session and exit out of all of the windows, the session is killed. This can be seen in the screenshots below:
After exiting all the windows of the vpnserver session, tmux ls shows that the session has been killed:
Finally, if you need to kill all the tmux sessions on a machine, you can use the following command:
As shown in the screenshot below, two tmux sessions are running, webdev and vpnserver. If you run the kill-server command, both sessions are killed:
To start a tmux session, use the following command:
To detach from the current tmux session, use the following tmux key combination:
Ctrl + b d
To reattach to a tmux session, use the following command:
To rename a tmux session, use the following command:
You can also rename the currently running tmux session using the following tmux key combination:
Ctrl + b ,
Furthermore, you can use the following command to kill a tmux session:
One of the most critical gaps in traditional Large Language Models (LLMs) is that they…
Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…
What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…
Wouldn’t it be wonderful to wake up one day with a desire to explore AI…
Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…
Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…