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!

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

System Admin Handbook

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

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources