04. Session Management tmux

Sessions are used to separate out completed unrelated workspaces. One of the sessions started can be for actual company work, while another session can be for our own personal side project. We can keep track of these sessions by names, and close (dettach) and open (reattach) them with their current states saved.

7 Commands for Session Managemt

1) Creating a new Session

The moment you start Tmux with the tmux command, you're placed in a session. If you'd like to name the session, use the new subcommand:

$ tmux new -s work

Here, we named our session "work". We can also use the keystroke:

2) Renaming a session

To rename our session to "play", simply by using the rename-session subcommand:

$ tmux rename-session play

Or use the keystroke:

<Ctrl-b> ,

3) Show all sessions

To get a listing of all sessions, type Ctrl-b s or type:

$ tmux list-sessions
# Same as:
$ tmux ls
work: 2 windows (created Tue Dec 22 14:00:52 2015) [85x24]

4) Detaching

Detaching means to save the session, unlike just exiting, which doesn't save. This feature is one of the hallmarks of tmux, and is what makes it persistent. To detach the current session, use the keystroke:

<Ctrl-b> d

Or the command:

$ tmux-detach

5) Attaching

Attaching a session is used to return back to a previous session that you detached from. To re-attach a session, use:

$ tmux attach -t work

The name of the session can be found from the list-sessions subcommand as shown above.

6) Switching

To switch to a particular session, use either the keystroke:

$ tmux switch -t session_name

7) Destroying

To get rid of a session, type:

<Ctrl-b> d

Sharing Sessions

Probably the coolest feature of sessions is that you can share it with other users, much like a Google Docs file. This means that if two users are SSH'ed into a remote host, and are using the same session, they can see exactly what the other is typing in real-time.

Sharing sessions on tmux is fun and perfect for paired programming!
Sharing sessions on tmux is fun and perfect for paired programming! Notice you can tell how big the other user has their terminal set with the green lines.

With one tmux session open, try opening up a new terminal window and attaching that same session.

$ tmux list-sessions
base: 1 windows (created Tue Dec 22 13:04:34 2015) [80x24] (attached)
$ tmux attach -t base

You should now have control of both windows! This won't be of any use alone, so go make some friends and perhaps you guys can have a fun paired-programming session!

Take your Linux skills to the next level!

The Linux Command Line

Take your Linux skills to the next level! Try Linux & UNIX

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Ad