Tmux Cheatsheet: Navigating Sessions Like a Pro

ยท 305 words ยท 2 minute read

Tmux Cheatsheet: Navigating Sessions Like a Pro ๐Ÿ”—

Are you tired of forgetting how to use tmux on Linux? Look no further! This cheatsheet will help you master tmux session management and navigation.

What is Tmux? ๐Ÿ”—

Tmux (Terminal Multiplexer) is a powerful tool that allows you to create multiple terminal sessions within a single window. It’s especially useful for remote work, as it enables you to detach from and reattach to sessions without losing your work.

Session Management ๐Ÿ”—

Create a new session ๐Ÿ”—

tmux new-session -s session_name
# or
tmux new -s session_name
  • -s: Specify a session name

List sessions ๐Ÿ”—

tmux list-sessions
# or
tmux ls

Attach to a session ๐Ÿ”—

tmux attach-session -t session_name
# or
tmux attach -t session_name
  • -t: Target session name

Detach from a session ๐Ÿ”—

tmux detach

Or use the key binding: Ctrl-b d

Switch between sessions ๐Ÿ”—

tmux switch-client -t session_name
  • -t: Target session name

Common Key Bindings ๐Ÿ”—

  • Ctrl-b d: Detach from current session
  • Ctrl-b s: List sessions
  • Ctrl-b $: Rename current session
  • Ctrl-b (: Switch to previous session
  • Ctrl-b ): Switch to next session

Pro Tips for Linux Users ๐Ÿ”—

  1. Start tmux automatically on SSH login by adding the following to your .bashrc or .zshrc:

    if [[ -z "$TMUX" ]] && [ "$SSH_CONNECTION" != "" ]; then
        tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux
    fi
    
  2. Create a tmux configuration file (~/.tmux.conf) for custom settings:

    # Example: Change prefix key to Ctrl-a
    set -g prefix C-a
    unbind C-b
    bind C-a send-prefix
    
  3. Use tmux plugins for enhanced functionality (install with Tmux Plugin Manager - TPM)

Remember: Practice regularly to build muscle memory for tmux commands and key bindings!

Conclusion ๐Ÿ”—

With this cheatsheet, you’ll never forget how to navigate between tmux sessions or how to detach and attach again. Keep it handy, and soon you’ll be managing your terminal sessions like a pro!