Using tmux

Posted on Wednesday, January 21, 2015

I am familiar wiht gnu screen commands http://www.gnu.org/software/screen/
[1]. I am trying to transition to using tmux instead of gnu screen.
I need to familiarize myself with the commands tmux uses vs what gnu screen. With that in mind I am going to explore and
write down some common commands in tmux.

If you just want a list of command equivalent (screen -> tmux) just scroll to the bottom of this post, I made a table.

Start a tmux session, detach, list and re-attach.

I am running this on an Ubuntu 14.04 server using Tmux vs
1.9a

To start a new session run the following command

> tmux

Here is the tmux default screen

To stop this session simply run the exit command

> exit

This will close the tmux session

If you want to leave the tmux session up you need to detach
from it. To detach from it press Ctrl+b
then press d. (On screen it is Ctrl+a then press d)

After doing that you will see a message like this

"[detached (from session 0)]"

To list all sessions currerntly running, run the following
command

> tmux list-sessions

Or you can use the shorter version

> tmux ls

In screen the command would be "screen -ls"

If there is only one session open to reattach to it run the following
command.

> tmux attach

Or the shorter version

> tmux a

In Screen the command would be "screen -a"

Name a session and reattach to it

If you start multiple sessions how do you reattach to the
correct one?

Here I have two sessions

The section before the colon contains the name. The second session has the name "1"

To reattach to it run the following command

> tmux attach -t 1

Screen's command would be"screen -r 1"

To create a session with the custom name "tail_log"
run the following command.

> tmux new -s tail_log

The session's name is in the lower left hand corner of tmux

To reattach to the named session run the following command.

> tmux attach -t tail_log

Creating a new session and detaching from it

Here is an example of creating a session and automatically
detaching from it.

> tmux new -s tail_log_2 -d

Creating new windows in a session and moving between
them

To create a new window in a session Ctrl+b then press c

To move between windows press Ctrl+b then n (for next)

Each window has a number starting at 0 to go to a specific
window press Ctrl+b then <number>
for example Ctrl+b then 0 goes to the first window.

To name a window press Ctrl+b then "," Then enter in name of window

Renaming it to "First Window"

Tmux panes

You can display multiple panes (windows) in one tmux
session.

Pressing Ctrl+b then %
will start up a new session and split the screen Vertically.

Pressing Ctrl+b then " will split the screen
Horizontally

.

To move around the panes press Ctrl+b then o. You can also use Ctrl+b then Up, Down, Left,
or Right.