Open In App

Tmux in Linux

Last Updated : 02 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Tmux, short for “terminal multiplexer,” is a powerful command-line tool in Linux that enables users to manage multiple terminal sessions within a single window. It allows for the creation and manipulation of multiple panes and windows, facilitating multitasking and efficient workflow organization. Tmux is particularly useful for remote sessions and long-running tasks, as it persists even if the connection is lost. With features like session sharing and customization, Tmux enhances productivity and flexibility in terminal-based environments.

What is Tmux in Linux?

tmux is a terminal multiplexer for Unix-like operating systems, including Linux. It allows you to create and manage multiple terminal sessions within a single terminal window or console. With this, you can split your terminal into multiple panes, navigate between them, and run different commands in each pane simultaneously. It has one of the key features you can flexibly detach the particular terminal session from getting disconnected. Later on, you can again re-attach the terminal session as per the requirement. It provides great speed & flexibility while maintaining the terminal sessions.

Features of Tmux:

  1. Session Management: You can create multiple sessions, each with its own set of windows and panes. Sessions can be detached and reattached, allowing you to disconnect from a session and later resume it.
  2. Window Management: Within each session, you can have multiple windows. Each window can contain one or more panes, and you can easily switch between windows to organize your work.
  3. Panes: Panes allow you to split a window into multiple resizable sections, each running its command. This makes it easy to monitor multiple processes or perform different tasks in parallel within a single terminal window.
  4. Customization: tmux is highly customizable. You can customize the status bar, key bindings, and other aspects of its behavior to suit your preferences.

Commonly Used Navigations in Tmux

Key

Description

Ctrl+B D

It will detach from the current session.

Ctrl+B %

It will split the window into two panes horizontally.

Ctrl+B ”

It will split the window into two panes vertically.

Ctrl+B Arrow Key (Left, Right, Up, Down)

It helps in moving between panes.

Ctrl+B N or P

It helps in switching the next or previous window.

Ctrl+B C

It will create a new window.

Ctrl+B X

It will close the pane

Ctrl+B 0 (1,2…)

It will move to the particular window by number.

Ctrl+B :

Enter the command line to type commands.

Ctrl+B ?

It will display all key bindings.

Ctrl+B W

It opens a panel to navigate across windows in multiple sessions.

Installation of Tmux in Debian-based Linux

In the many Linux distributions, tmux comes pre-installed on the system. But sometimes if it is not installed then we need to manually install it on the system. For this demonstration “Kali Linux” is used as a platform. Since Kali Linux is Debian-based Linux, so apt package manager is used to install the packages and their dependencies.

Command:

sudo apt install tmux
  • apt: It helps to manage software installation and removal on Debian-based Linux distribution.

Installation of Tmux

Practical Examples of Tmux Command

There are many uses of the tmux command which can be used to get the job done easily. In the given below, there are some practical use cases of the tmux command.

1. Launch a New Tmux Session:

After installation of tmux, we can simply launch the tmux session by simply writing “tmux” on the command prompt.

Command:

tmux

Launching New Tmux Session

2. Assigning a session name:

If you want to work into the multiple tmux’s session then you can name the session according to your choice. This will help you to identify tasks related to that session.

Command:

tmux new -s s1
  • new: To create a new session
  • -s: It is used to give the name for a new session

Assigning a session name

3. Split the Window into two Panes Horizontally:

This command of tmux allows us to split the window session horizontally. This feature allows to creation of multiple horizontal panes at the same time. It helps in working more efficiently when you are working on multiple things within a directory or any file location.

Syntax:

Ctrl +b, %

Press the (ctrl + b) followed by (shift + %) to perform the splitting of the window into panes.

Spliting Window into Two Horizontal Panes

4. Split the Window into Two Panes Vertically:

This command of tmux gives us great features to split a window session vertically. This allows us to create more vertical panes at the same time. This helps in working multiple things within the same directory or same location.

Syntax:

Ctrl + b, "

Press the (ctrl + b) followed by (shift + “) to operate.

Spliting Window into two Vertical Panes

5. Create a New Window:

This command of tmux allows us to create a new session window within the terminal. The users can create multiple new window sessions required for their work purposes.

Syntax:

Ctrl + b, c

Press the (ctrl +b) followed by press (c) to create a new window.

Create New Window

6. Detach the Window from the Current Session:

This command of tmux allows us to minimize any window session in the background. This helps in detaching any unnecessary opened windows session which is not required at a time. The process of the session keeps running in the background so it will prevent any loss of data.

Syntax:

Ctrl + b, d

Press (ctrl + b) followed by (d) to detach the session.
Detach Window from Current Session

7. List the Existing Sessions:

This command of tmux allows us to list all the sessions that are running in the background and also detach from the current session. We can see the details as session name, date, and time of creation.

Command:

tmux list-sessions
  • list-sessions: It will list the entire tmux’s sessions which are currently running in the background or detached from the session

List the Existing Sessions

8. Attach to a Session:

The session that was detached before can make use of this command to re-attach the session for their work purpose. This is a great functionality of tmux that users can re-attach any session at any time without losing their data.

Syntax:

tmux attach-session -t session_name
  • attach-session: It will attach a session as per the name given by the name.
  • -t: It is used to assign the session’s name provided by the user.

Command:

tmux attach-session -t s1

Attach to a Session

9. Rename the Session Name:

This command of tmux allows us to rename the session with the combination of alphanumeric values. The users can choose any sort of name as per their choice or work preference.

Syntax:

tmux rename-session -t old_session-name new_session-name
  • rename-session: It is used to rename the session’s name.
  • -t: It is used to assign the session’s name provided by the user.

Command:

tmux rename-session -t s1 newses1

Rename the Session Name

10. Terminating/Kill the Session:

This command of tmux allows us to terminate or kill the session which is no longer required for use.

Syntax:

tmux kill-session -t session_name
  • kill-session: It will terminate the session.
  • -t: It is used to assign the session’s name provided by the user.

Command:

tmux kill-session -t newses1

Killing the Session

To verify whether the session is killed/terminated or not, we can execute the below command in the terminal.

tmux list-sessions

Verifying Session Termination

Conclusion

In conclusion, tmux is like having a fantastic tool for computer work management when you use Linux. It makes multitasking easier by allowing you to perform multiple tasks at once in the terminal. since it allows you to personalize and manage your terminal in a way that works best for you. It is faster, and more reliable in multi-tasking which helps to save a lot of time while managing the different tasks.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads