100 Useful Command-Line Utilities
by Oliver; 201466. tmux
Note: tmux is not a default shell program. You may have to download and install it.As discussed in An Introduction to the Command-Line (on Unix-like systems) - tmux, tmux is a more modern version of screen, which all the cool kids are using. In tmux there are:
- sessions
- windows
- panes
I'm showing off by logging into three different computers—home, work, and Amazon.
Start a new session:
$ tmuxDetach from your session: Leader d, where the leader sequence is Cntrl-b by default.
List your sessions:
$ tmux ls 0: 4 windows (created Fri Sep 12 16:52:30 2014) [177x37]Attach to a session:
$ tmux attach # attach to the first session $ tmux attach -t 0 # attach to a session by idKill a session:
$ tmux kill-session -t 0 # kill a session by id
Here's a more systematic list of commands:
<Leader> c | Create a new window |
<Leader> x | Kill the current window |
<Leader> n | Go to the next window |
<Leader> p | Go to the previous window |
<Leader> l | Go to the last-seen window |
<Leader> 0-9 | Go to a window numbered 0-9 |
<Leader> w | List windows |
<Leader> s | Toggle between sessions |
<Leader> d | Detach the session |
<Leader> , | Set a window's title |
<Leader> [ | Start copy mode (which will obey vim conventions per order of the config file) |
<Leader> ] | Paste what you grabbed in copy mode |
<Leader> % | Spawn new horizontal pane (within the window) |
<Leader> " | Spawn new vertical pane (within the window) |
<Leader> o | Go to the next pane (within the window) |
<Leader> o (pressed simultaneously*) | Swap position of panes (within the window) |
<Leader> q | Number the panes (within the window) - whereupon you can jump to a specific pane by pressing its numerical index |
<Leader> z | Toggle the expansion of one of the panes (within the window) |
<Leader> t | Display the time |
<Leader> m | Turn mouse mode on (allows you to resize panes with the mouse) |
<Leader> M | Turn mouse mode off |
<Leader> : | Enter command mode |
* With tmux, in contrast to screen, you give a slightly longer pause after pressing the Leader sequence. In this particular case, however, they are pressed simultaneously.
As before, I like to use Cntrl-f as my Leader sequence. Here's a sample .tmux.conf file, which accomplishes this, among other useful things:
### Default Behavior # Use screen key binding set-option -g prefix C-f # 1-based numbering set -g base-index 1 # Fast command sequence - cause some error # set -s escape-time 0 # Set scrollback to 10000 lines set -g history-limit 10000 # Agressive window setw -g aggressive-resize on ### Views # Highlight Active Window set-window-option -g window-status-current-bg red # Status Bar set -g status-bg black set -g status-fg white set -g status-left "" set -g status-right "#[fg=green]#H" ### Shortcut # Last Active Window bind-key C-a last-window # set -g mode-mouse on # vi bindings in copy mode set-window-option -g mode-keys vi # Tmux window size ( http://superuser.com/questions/238702/maximizing-a-pane-in-tmux ) unbind + bind + new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \; swap-pane -s tmux-zoom.0 \; select-window -t tmux-zoom unbind - bind - last-window \; swap-pane -s tmux-zoom.0 \; kill-window -t tmux-zoomTo reload .tmux.conf after making changes: <Leader> :source-file ~/.tmux.conf
To copy and paste text, assuming vi bindings:
- first enter copy mode with <Leader> [
- copy text with space to enter visual mode, then select text, then use y to yank, then hit Enter
- paste text with <Leader> ]
$ tmux attachand now you're running tmux within tmux. To execute tmux commands on the inner session, use Cntrl-b after the <Leader> sequence. For example, to list your windows on the inner session, you'd type <Leader> Cntrl-b w.
tmux is amazing—I've gone from newbie to cheerleader in about 30 seconds!
Hat tip: Albert