Skip to content

Instantly share code, notes, and snippets.

@gregtoth
Last active January 30, 2022 09:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gregtoth/6675eaf1e19ec44d52fd3aec2cb050f7 to your computer and use it in GitHub Desktop.
Save gregtoth/6675eaf1e19ec44d52fd3aec2cb050f7 to your computer and use it in GitHub Desktop.
Tmux Cheatsheet

Tmux Cheatsheet

Tmux is a "terminal multiplexer" that makes it much easier to run multiple programs over a single ssh session. It lets you create multiple virtual terminals within a single ssh login, allowing you to easily flip between each virtual terminal. Each virtual terminal works like a regular terminal but has the added benefit that if you lose the overall ssh session you can log back in and re-attach to the tmux session and all your virtual terminals are still there where you left off. This also allows you to start one or more programs within virtual terminals, detach the tmux session, logout your ssh session, login via ssh a some point in the future, re-attach to your tmux session, and all your previous virtual terminals are exactly where you left off. Programs you run in virtual terminals continue to run while you're detached and/or while you're logged out all-together.

Shell cmd Action
tmux Start tmux
tmux ls Show existing tmux sessions
tmux attach Re-attach to last active session
tmux attach -t 2 Re-attach to session 2
tmux attach -t logs Re-attach to session named "logs"
tmux rename -t 2 logs Rename session 2 to "logs"

Commands Inside Tmux Sessions

Default Prefix key is Control-B. Can be changed in ~/.tmux.conf

Command Action  
Ctrl-B d Detach from current session
Ctrl-B c Create new window
Ctrl-B n Change to next window
Ctrl-B p Change to previous window
Ctrl-B w Choose the current window from a list
Ctrl-B r Redraw the window
Ctrl-B " Split current pane in two, horizontally
Ctrl-B % Split current pane in two, vertically
Ctrl-B o Select next pane in current window
Ctrl-B SPACE Toggle current pane layout between horizontal/vertical
Ctrl-B ? List all key bindings
Ctrl-B [ Enter back-scroll mode Navigate through back-scroll lines using vi keys, Ctrl-P, Ctrl-B, etc.
q Exit back-scroll mode
Ctrl-B x Kill the current window or pane
exit Exit the active shell within a tmux window or pane

Default settings and key bindings are controlled through ~/.tmux.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment