> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Attach and Detach a Session in Tmux
- URL: https://linuxhandbook.com/tmux-attach-detach-session/
- Published: 2024-12-05T10:35:53.000Z
- Updated: 2024-12-05T10:42:19.000Z
- Description: The very basics of tmux. Learn to attach and detach a session in tmux.
- Author: Pranav Krishna
- Tags: Exploring Tmux, #docs-col

Tmux, the most used tool for *multitask(plex)ing* in the command line, has one important feature that takes it to the next level: sessions. 

You can attach to an ongoing session and detach from it, which is pretty useful in a server environment since the sessions will be preserved for months anyway. 

Here's how you can attach to and detach from sessions in Tmux.

## Detaching from a session in tmux

Consider a [tmux](https://linuxhandbook.com/tmux/) session, where you have multiple panes and windows. To detach from this session, the shortcut is:

```
[Ctrl+B] + d
```

Here, `Ctrl+B` is the modifier key, and `d` stands for detach. 

This will immediately detach you from the session, while keeping the processes running in the background. 

![Detach from tmux session](https://linuxhandbook.com/content/images/2024/11/tmux-detach-session.gif)

Detach from tmux session

## Attaching to session in tmux

You can attach to the previously connected session immediately by running the command:

```bash
tmux attach
```

![Attach to a session directly](https://linuxhandbook.com/content/images/2024/11/tmux-attach-session-direct.gif)

Attach to a session directly

### Managing multiple sessions

Generally, there may be multiple sessions, organised properly for different purposes. That's when the ls command comes in handy. Use that first to list all the running sessions: 

```bash
tmux ls
```

![tmux ls](https://linuxhandbook.com/content/images/2024/11/tmux-ls.png)

Example of tmux ls

To attach to a particular session, you can use the relevant name or number, as shown here:

```bash
tmux attach -t <name>
```

![Attach to session by specifying target](https://linuxhandbook.com/content/images/2024/11/tmux-attach-session.gif)

Attach to the session by specifying the target

## Conclusion 

Tmux can be the ultimate productivity tool when used with all possible splits, such as panes, workspaces and sessions. 

You might notice above that the target session has a custom name rather than number indexes. [Renaming tmux session](https://linuxhandbook.com/tmux-rename-session/) is the best method to neatly organize your sessions. The next part of the series deals with the same, see ya there.