Using tmux

Server Photo by Sergei Starostin, Pexels

tmux Cheat Sheet

I can never quite remember the routine for setting up a long running job on a server using nohup, more specifically the 2>&1 routine to divert output into a log file i.e. nohup run something log.log 2>&1 &. Which sounds trivial, but I’ve had a few prompts to start using tmux.

Mental Model

Rightly or wrongly, I think of tmux as a terminal that keeps running after I disconnect.

SSH --> tmux session --> run jobs
          ^
          |
    reconnect later

Starting

Create a new session:

tmux new -s mysession

Detach From a Session

This is easy, but weird when I think Ctrl-b moves a character one backwards:

Ctrl-b d

This leaves everything running and I can log out.

List Sessions

Logging back in, if I can’t remember what I called the session (!)

tmux ls

Reattach to a Session

tmux attach -t age_std

or, if only one session exists:

tmux attach

Kill a Session

tmux kill-session -t age_std

Windows (Like Tabs)

Create a new window with:

Ctrl-b c

Next window:

Ctrl-b n

Previous window:

Ctrl-b p

List windows:

Ctrl-b w

Useful Checks

See whether a job is still running:

ps -ef | grep run

Inside tmux:

top

Most Used Commands

tmux new -s name
tmux ls
tmux attach -t name
tmux kill-session -t name

And one keyboard shortcut:

Ctrl-b d