In Linux, the tmux command creates multiple terminal screen sessions to run more than one program in one terminal simultaneously. Using this, users can attach and detach the particular terminal session according to their requirements. It also facilitates the user with various features such as splitting into multiple windows. When the user gets disconnected from the session, the data is saved and can be re-attached easily.
This article will address the installation method of tmux and will guide how tmux manages multiple sessions.
- How to Install tmux Command?
- How to Manage Multiple Terminal Sessions?
- How to Kill the tmux Terminal Sessions?
How to Install tmux Command?
The tmux is not pre-installed in the operating system, the user can install it through the given command depending upon your Linux distributions:
$ sudo apt install tmux #For Debian/Ubuntu $ sudo yum install tmux #For Fedora/CentOS/RHEL $ sudo pacman -S tmux #For Arch $ sudo zypper install tmux #For OpenSUSE
How to Manage Multiple Terminal Sessions?
The tmux command gives the facility to manage sessions such as creating multiple sessions, attaching to the created sessions, split the terminal sessions horizontally, and vertically. Let’s practice these in the following examples:
Example 1: Create the Session
To create the multiple sessions session, utilize the “s” flag and specify the names of the session separated by commas:
$ tmux new -s session_1
The session has been created with the name “session_1” as provided. Press the “Ctrl+B” and then “D” to detach from the session.
Example 2: Attach to Created Session
To re-attach to the created session you can use the “attach” keyword with the “t” flag and specify the name of the particular session:
$ tmux attach -t session_1
The user has been reattached to the session “itslinuxfoss”.
Note: Using the “tmux attach” without the name of the session, will attach you to the last created session.
Example 3: Split Multiple Sessions Horizontally
To split the session into multiple terminals horizontally, press the “Ctrl+B” and then “Shift+D” from the keyboard:
The session has been split horizontally.
Example 4: Split Multiple Sessions Vertically
Likewise, to split the terminal session vertically, press the “Ctrl+B” and then “Shift+5”(%) from the keyboard:
The session has been split vertically.
Example 5: Split the Sessions Vertically and Horizontally
The user can also split both vertically and horizontally simultaneously as shown in the below image:
The user can switch between the split screens by pressing “Ctrl+B” and then the arrow keys (left, right, up, and down).
How to Kill the tmux Terminal Sessions?
To kill the tmux terminal sessions, use the “kill-session” in the command along with the “t” flag and specify the name of the terminal session:
$ tmux kill-session -t itslinuxfoss
To remove all terminal sessions, use the “kill-server” option with the tmux command:
$ tmux kill-server
All terminal sessions will be demolished.
Let’s verify it by listing the terminal sessions:
$ tmux ls
As all the sessions have been deleted, so there is no terminal session present.
In Linux, the tmux is the utility to create and manage terminal sessions such as attaching, detaching, or splitting the screen horizontally or vertically. This post has illustrated the tmux command to manage terminal sessions. Apart from this, the removing method of the terminal sessions has also been illustrated in this post.