Skip to content

TMUX CHEATSHEET

From the site: tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

COMMANDS

TERMINAL COMMANDS

  • tmux new - Create and attach to a new session.
  • tmux new -s SESSION-NAME - Create and attach to a new session named SESSION-NAME
  • CTRL-b, d - Detach from the currently-opened tmux session
  • tmux ls - Show list of tmux sessions
  • tmux a - Attach to the previously-opened tmux session
  • tmux a -t SESSION-NAME - Attach to the tmux session named SESSION-NAME

TMUX COMMANDS

  • CTL-d - Delete currently-opened tmux session (alternatively tmux kill-session)
  • CTL-b, [ - Enter copy mode, and enable scrolling in currently-opened tmux session. Press q to exit
  • CTL-b, " - Split window horizontally
  • CTL-b, % - Split window vertically
  • CTL-b, UpArrow - Move to the pane above
  • CTL-b, DownArrow - Move to the pane below
  • CTL-b, LeftArrow - Move to the pane to the left
  • CTL-b, RightArrow - Move to the pane to the right
  • CTL-b, z - Toggle maximization of current pane
  • CTL-b, ESC, 2 - Resize all panes to equal size
  • CTL-b, q - Show pane numbers
  • CTL-b, x - Kill current pane
  • CTL-b, c - Create a new window
  • CTL-b, n - Switch to next window
  • CTL-b, p - Switch to previous window
  • CTL-b, 3 - Switch to window 3
  • CTL-b, CTL-b, COMMAND - Send the command to a nested tmux session (repeat prefix for each level of nesting)

SHARED SESSIONS

CREATE SESSION

    tmux new-session -s SESSION-NAME

ATTACH TO SESSION

    tmux attach-session -t SESSION-NAME

ALLOW OTHER USERS TO ATTACH TO SESSION

Pay attention to the vernacular here, we have three things that need to be paid attention to:

  • Socket to be shared
  • Session to be shared
  • Common group to all involved users

  • Ensure that a common group exists between users, or create one

    useradd -G user1 user2 user3
    
  • Create socket

    tmux -S /tmp/SHARED-SOCKET-NAME new -s SHARED-SESSION-NAME
    
  • Fix permissions

    chgrp SHARED-GROUP-NAME /tmp/SHARED-SOCKET-NAME
    
  • Attach

    tmux -S /tmp/SHARED-SOCKET-NAME attach -t SHARED-SESSION-NAME
    
    or for read-only:
    
    tmux -S /tmp/SHARED-SOCKET-NAME attach -t SHARED-SESSION-NAME -r