Need to monitor different commands at the same time in your terminal? tmux, a terminal multiplexer, makes it easy to split your terminal into multiple panes and run different commands simultaneously. Here’s how.
The Basic Command
tmux new-session "ls; exec zsh" \; split-window -h -p 66 "ls; exec zsh" \; split-window -h -p 50 "ls; exec zsh"
Let’s break this down:
tmux new-session
: Starts a new tmux session"ls; exec zsh"
: Runs thels
command and then starts a new zsh shellexec zsh
: Keeps the pane open by replacing the current process with a new shell
split-window -h -p 66
: Creates a horizontal split, giving 34% to the first panesplit-window -h -p 50
: Creates another horizontal split, dividing the remaining space equally\;
: Separates tmux commands (note the backslash before semicolon)
Customizing The Layout
You can adjust the splits by modifying the -p
values:
- For two equal panes: use
-p 50
- For three equal panes: use
-p 66
followed by-p 50
- For vertical splits (one above another): replace
-h
with-v
Using Different Shells
The command above uses zsh, but you can use bash instead:
tmux new-session "ls; exec bash" \; split-window -h -p 66 "ls; exec bash" \; split-window -h -p 50 "ls; exec bash"
Practical Uses
This setup is perfect for:
- Monitoring system resources in different panes
- Running and watching multiple processes
- Comparing command outputs in real-time
- Managing multiple git repositories
Once you’re in tmux, you can navigate between panes using Ctrl-b
followed by arrow keys. Try it out and customize the commands to fit your workflow!