TMUX

Installing tmux

The following command installs tmux from the snap repositories.

sudo snap install tmux

In the case that snap is is not installed on the ubuntu server type in:

sudo apt install snapd

Starting & Exiting Tmux

  • tmux – Start a new tmux session
  • tmux new -s <name> – Start a new named session
  • tmux attach -t <name> – Attach to an existing session
  • tmux detach (Ctrl-b d) – Detach from the current session
  • tmux list-sessions – List all active sessions
  • tmux kill-session -t <name> – Kill a specific session
  • tmux kill-server – Kill all sessions and exit tmux

Ctrl – b commands:

When Ctrl + b is used in a command that means that the user must press Ctrl + b then release the key combo before continuing with the rest of the command. An example would be to split the Terminal vertically the user would need to press Ctrl + b, release then press shift + 5.

Pane Management

  • Ctrl-b % – Split the window vertically
  • Ctrl-b " – Split the window horizontally
  • Ctrl-b o – Switch between panes
  • Ctrl-b ; – Move to the last active pane
  • Ctrl-b x – Close the current pane
  • Ctrl-b z – Toggle pane zoom
  • Ctrl-b { – Move pane left
  • Ctrl-b } – Move pane right

Window Management

  • Ctrl-b c – Create a new window
  • Ctrl-b n – Switch to the next window
  • Ctrl-b p – Switch to the previous window
  • Ctrl-b w – Choose a window interactively
  • Ctrl-b , – Rename the current window
  • Ctrl-b & – Close the current window

Session Management

  • tmux rename-session -t <old_name> <new_name> – Rename a session
  • tmux switch -t <name> – Switch to a different session
  • tmux detach-client -s <name> – Detach a client from a session

Scrolling & Copy-Paste

  • Ctrl-b [ – Enter scroll mode (use arrow keys or PgUp/PgDn)
  • Space – Start selection
  • Enter – Copy selection
  • Ctrl-b ] – Paste

Resizing Panes

When resizing Terminal panes, the easiest way is to press and HOLD the Ctrl + B and then use the arrow keys on the keyboard to resize the current window as needed. This is a much easier way than typing in the command.

  • Ctrl-b : resize-pane -D 5 – Resize pane down
  • Ctrl-b : resize-pane -U 5 – Resize pane up
  • Ctrl-b : resize-pane -L 5 – Resize pane left
  • Ctrl-b : resize-pane -R 5 – Resize pane right

Personal TMUX Preference on sign-in.

You can add and modify a tmux script so that one pane starts btop (a system monitor) and another starts ranger (a file manager). Here’s how:

tmux Script

#!/bin/bash

# Start a new tmux session named 'mysession' (detached mode)
tmux new-session -d -s mysession

# Split the window vertically (equivalent to Ctrl + b %)
tmux split-window -h -t mysession

# Split the first pane horizontally (equivalent to Ctrl + b ")
tmux split-window -v -t mysession:0.0

# Start 'btop' in the top-left pane
tmux send-keys -t mysession:0.0 'btop' C-m

# Start 'ranger' in the bottom-left pane
tmux send-keys -t mysession:0.1 'ranger' C-m

# Attach to the tmux session
tmux attach -t mysession

What This Script Does

  1. Creates a tmux session named mysession.
  2. Splits the screen vertically (Ctrl + b %).
  3. Splits the left pane horizontally (Ctrl + b "), resulting in three panes:
    • Top-right pane → Runs btop.
    • Bottom-right pane → Runs ranger.
    • Left pane → Remains free (you can use it for other commands).
  4. Sends commands to start btop and ranger in their respective panes.
  5. Attaches to the session so you can interact with it immediately.

Create Script File

sudo nano ~/tmux-script.sh
Enter in the script above and make changes to desired preference.
Save by pressing ctrl + O
Exit by pressing ctrl + X

Run the Script

To run the script simply type in ~/tmux-script.sh

Optional: Make it Run on Login

If you want tmux to start automatically when you log in:

sudo nano ~/.bashrc: nano ~/.bashrc
Add the following at the bottom:
if [[ -z "$TMUX" ]]; then ~/start_tmux.sh fi
Save the changes by pressing ctrl +
Exit with ctrl + x

Similar Posts