2024-10-07
Before diving into commands, make sure tmux is installed on your system. Most Linux distributions include it in their package managers. For example:
sudo apt update && sudo apt install tmuxsudo dnf install tmuxsudo pacman -S tmuxOnce installed, simply type tmux in your terminal to launch it. You’ll now be in a tmux session.
Tmux employs a simple keybinding system using the prefix key, usually Ctrl+b (configurable). Let’s look at essential pane commands:
Creating Panes:
Ctrl+b %: Splits the current pane horizontally.Ctrl+b ": Splits the current pane vertically.Switching Panes:
Ctrl+b arrow keys: Navigate between adjacent panes.Ctrl+b o: Cycle through panes in a circular order.Resizing Panes:
Ctrl+b Shift+arrow keys: Resize the current pane.Example: Setting up a development environment
Let’s imagine you’re working on a project requiring multiple terminal sessions. You might use tmux to set this up:
tmuxCtrl+b "python3 -m http.serverpython3 my_app.pyNow you have both your server and application running side-by-side, easily managed within a single tmux session.
Tmux allows you to work with multiple windows within a session, further enhancing organization.
Creating Windows:
Ctrl+b c: Creates a new window. You’ll be prompted to name it.Switching Windows:
Ctrl+b n: Switch to the next window.Ctrl+b p: Switch to the previous window.Ctrl+b <number>: Switch to window number <number>.Killing Windows:
Ctrl+b &: Kills the current window.Example: Organizing tasks
Suppose you have many different tasks: database management, code editing, and system monitoring. You could use different windows for each:
Ctrl+b c and name it “Database”psqlCtrl+b c and name it “Code”Ctrl+b c and name it “Monitoring”top or another system monitoring tool.Now you have a clearly organized workspace with each task in its own window.
One of tmux’s most powerful features is the ability to detach from a session and reattach later. This saves your work even if you close your terminal.
Detaching:
Ctrl+b d: Detaches from the current tmux session.Reattaching:
tmux attach: Reattaches to your last session. If you have multiple sessions, you might need to use tmux attach-session -t <session_name> to specify.Listing sessions:
tmux ls: Lists all active tmux sessions.Tmux offers extensive configuration options through the ~/.tmux.conf file. You can customize your prefix key, keybindings, and much more. For example, to change the prefix key to Ctrl+a:
set -g prefix C-a
This file allows for powerful customization of your tmux experience. Exploring the possibilities within this configuration file can improve your productivity.