Horje
Tmux in Linux

Tmux is a short form for “terminal multiplexer,“. It 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?

The 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.

Options of Tmux in Linux

The following are the options of Tmux in Linux:

Option Description
Session Management It helps to Create, manage, and switch between multiple Tmux sessions.
Window Management It facilitates with spliting of windows horizontally or vertically, rename, and navigate between them.
Configuration It support customization of Tmux behavior using configuration files (~/.tmux.conf).
Integration It provides a seamless integration with terminal applications like Vim, SSH, and more.
Plugins It is capable of extend functionality with third-party plugins for additional features.

Key Features of Tmux Command

The following are the features of Tmux Command:

  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

The following are the some of the commonly used navigations in Tmux Command:

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.

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

Difference between Tmux and Screen

The following are the difference between Tmux and Screen:

Feature Tmux GNU Screen
Development Status It is actively developed and maintained command In this development has slowed down, less active maintenance.
Window Management It is more flexible and intuitive window splitting and management. It is basic window splitting and management capabilities.
Configuration It is highly configurable with a robust configuration system (~/.tmux.conf). In this configuration can be done but may require more effort.
Scripting Support It has good support for scripting and automation of tasks. It has the scripting capabilities exist but may be less extensive.

Advantages of Tmux

The following are the advantages of Tmux:

  • Efficient Session Management: It facilitates with easily creating, managing and switching between multiple terminal sessions.
  • Flexible Window and Pane layouts: It will split the windows into the multiple panes, providing the resizing the feature dynamically and helps in organzing the layouts for optimal multitasking.
  • Session Persistance: It has the ability to detach and reattach the sessions without losing of state and ideal for the long running tasks or remote sessions.
  • Customization and Scripting: It highly able customize through configuration files with extensive support for scripting to automate the tasks and personalize the workflows.

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.

Tmux in Linux – FAQs

How do I install tmux on Linux?

On using your system’ s package manager (e.g., sudo apt-get install tmux for Debian/Ubuntu) we can install tmux on Linux distributions.

Is tmux available for Windows?

Yes, tmux is available for Windows, It can download and installable through packages like Cygwin or Windows Subsystem for Linux (WSL).

What is the advantage of using tmux?

Tmux will improves the productivity with session management, window splitting, and customization options.

How do I run a program in tmux?

We can start the tmux (tmux) and then execute program with the (program_name).

How do I run tmux on startup?

On adding the tmux to your shell’s startup script (e.g., .bashrc or .zshrc) to start tmux automatically when you log in.




Reffered: https://www.geeksforgeeks.org


Geeks Premier League

Related
Find Real IP behind CloudFlare with CloudSnare Find Real IP behind CloudFlare with CloudSnare
What Is AlmaLinux What Is AlmaLinux
Nameerror: Name '__File__' Is Not Defined" in Python Nameerror: Name '__File__' Is Not Defined" in Python
Connecting to Greenplum in Tableau Connecting to Greenplum in Tableau
How to Exclude Property from Type in TypeScript ? How to Exclude Property from Type in TypeScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8