top of page

Want to run commands in the background? Use tmux!

tmux (terminal multiplexer) is a powerful command-line tool that allows you to manage multiple terminal sessions within a single window. It runs in the terminal and does not require a graphical user interface, making it a great choice for remote servers or resource-constrained environments. Additionally, Tmux's design minimises memory usage and CPU overhead, allowing it to run efficiently even on low-powered devices. If your SSH connection drops, tmux ensures your tasks continue running on the server, allowing you to reconnect without interruption.




Here’s a quick guide to using tmux in Linux:


Installing tmux

Run the following command in your terminal:

# On Debian/Ubuntu-based systems
sudo apt update && sudo apt install tmux

# On CentOS/RHEL-based systems
sudo yum install tmux

# On Fedora
sudo dnf install tmux

# On Arch Linux
sudo pacman -S tmux

Starting tmux

  • Start a new tmux session:

tmux
  • This opens a new session.

  • Start a named session:

tmux new -s session_name

Basic tmux Commands

Once inside tmux, commands are executed using a "prefix key" (default: Ctrl-b), followed by a specific key combination.

Session Management

  • Detach from a session:Press Ctrl-b then d (detach and leave the session running in the background).

  • List sessions:

tmux list-sessions
  • Reattach to a session:

tmux attach -t session_name
  • Kill a session:

tmux kill-session -t session_name

Window Management

  • Create a new window:Press Ctrl-b then c.

  • Switch between windows:Press Ctrl-b then a number (0, 1, 2, etc.) corresponding to the window index.

  • Rename a window:Press Ctrl-b then , and type the new name.

  • Close a window:Type exit in the window or press Ctrl-d.

Pane Management

  • Split the screen horizontally:Press Ctrl-b then %.

  • Split the screen vertically:Press Ctrl-b then ".

  • Navigate between panes:Press Ctrl-b then an arrow key.

  • Resize panes:Press Ctrl-b then Ctrl-arrow_key (e.g., Ctrl-b + Ctrl-Left).

  • Close a pane:Press Ctrl-b then x.


Exiting tmux

  • To close a tmux session, type exit in all panes or windows.

  • To kill all tmux sessions at once:

tmux kill-server

Do you use tmux? What do you think?

Comments


bottom of page