How to Exit tmux Window Without Quitting the Terminal Program?

In Linux, the tmux is the command that is considered for creating multiple screen sessions of the terminal. It is beneficial in a way to run more than one program in one terminal that facilitates the user to attach/detach the specific session. However, the user might want to exit from the terminal session once tasks are performed.

This post will demonstrate the methods to exit from the tmux window without quitting the terminal in Linux.

Note: Check out our guide here if you want to know about the tmux commands to manage multiple terminals and sessions.

Method 1: Using the Shortcut Key (Ctrl+B+D or Ctrl+A+D)

The quick and easiest way to exit from the tmux session without quitting the terminal program is by using the keyboard shortcut key. The following steps justify the implementation of this method:

Step 1: Create the tmux Session

Let’s create the tmux session using the following command in the terminal:

$ tmux new -s session_1

The tmux session is created with the name “session_1”.

Step 2: Press the “Ctrl+A” and Then “D” (To Exit the Session)

Now, to exit from the particular created session, press the shortcut key “Ctrl+A” and then “D” from the keyboard:

The tmux session is exited as shown in the above “GIF”.

Note: The whole session will be terminated, so the user can’t be able to re-attach.

Step 3: Press the “Ctrl+B” and Then “D” (To Detach the Session)

The user can also detach from the particular session using the shortcut “Ctrl+B” and then “D”:

The user has been detached from the particular session.

Note: Detaching the terminal will run the terminal session in the background that can be re-attachable.

Method 2: Using the “exit” Command

The second way to exit from the created tmux session is by using the “exit” command. The following steps show the accomplishment of this method. 

Step 1: Create the tmux Session

Create the tmux screen session using the “new” command by specifying the “session_1”:

$ tmux new -s session_1

The tmux session has been created.

Step 2: Run the “exit” Command

Now, type the “exit” command in the tmux session command in order to exit:

$ exit

After running the ”exit” command, the terminal session will be exited as shown:

$ tmux new -t session_1

Method 3: Using the “tmux detach” Command

The user can also use the “tmux detach” command that will detach the user from the particular session. Go through the subsequent steps to apply this method:

Step 1: Create the tmux Session

Create the new session by running the below-given command:

$ tmux new -s session_1

The “session_1” is created.

Step 2: Run the “tmux detach” Command

Type the “tmux detach” command to detach from the terminal session:

$ tmux detach

Once typed, hit the enter button:

$ tmux new -s session_1

The user has been detached from the session_1 as shown above.

Method 4: Using the “tmux kill-session” Command

The user can also use the “tmux kill-session” command along with the “t” flag to exit from the tmux-created session. The “t” flag is used for defining the tmux session name. Let’s apply this method in the subsequent steps.

Step 1: Create the tmux Session

Create the tmux screen session using the “new” command by specifying the “session_1” as shown:

$ tmux new -s session_1

The tmux session has been created.

Step 2: Run the “tmux kill-session” Command

To exit the current tmux session, run the “tmux kill-session” command along with the “t” flag and define the session name as shown:

$ tmux kill-session -t session_1

After running the above command, the session is exited as shown in the figure:

$ tmux new -s session_1

Conclusion

To exit from the tmux window, press the keyboard shortcut key “Ctrl+A” or “Ctrl+B” and then “D” or use the “exit”, “tmux detach” or “tmux kill-session” command. The combination of the “Ctrl+A+D” key exits the terminal session while the “Ctrl+B+D” key detaches the user from the terminal session. 

This write-up has illuminated the methods to exit from the tmux window without quitting the terminal program.