How To List and Attach Tmux Sessions?

Tmux is a popular Linux terminal that provides very useful features. Tmux provides the ability to make terminal sessions permanent even the SSH connection or current terminal is closed. tmux sessions can continue in the background and later these sessions can be easily listed and used again. In this tutorial, we learn how to list tmux sessions and select a tmux sessions.

List Tmux Sessions

The tmux sessions can be listed with the ls parameter. The ls parameter of the tmux is very similar to the bash ls command which lists files and folders. In this case the tmux ls command lists tmux sessions. While listing tmux sessions some information about these sessions provided too.

tmux ls
0: 1 windows (created Sun Apr 11 19:24:52 2021) (attached)
1: 1 windows (created Sun Apr 11 19:25:11 2021) (attached)
2: 1 windows (created Sun Apr 11 19:25:15 2021) (attached)
List Tmux Sessions

The following information about the listed tmux sessions are provided.

  • 0: is the session ID set by the tmux.
  • 1 windows is the name of the sessions which is set by default.
  • (created Sun Apr 11 19:24:52 2021) is the creation date and time of the session.
  • (attached) is the current status of the tmux session which means it is attached.

Attach Tmux Session

After listing sessions one of them can be easily attached by using its session name or session ID. The a parameter is used to attach sessions and -t is used to specify the session name or session ID we want to attach. In the following example, we attach the tmux session with the session ID 1.

tmux a -t 1

Alternatively the session name can be used to attach a session. In the following example we attach the tmux session named “mylinux”.

tmux a -t "mylinux"

Kill Session

After listing sessions we can kill a specific sessions if we do not need it anymore. The session ID or session name can be used to kill sessions. The “tmux kill-session” command can be used with the -t option where the session name or session ID is provided.

tmux kill-session -t 1

Leave a Comment