There are times when I have to log into Linux systems that don’t have window managers. I have a single terminal window in which to work. With the help of tmux, I can have multiple virtual windows in my single window. Each window can be split into panes. I can also save sessions so that I can bring the environment back after I disconnect from the system and reconnect several days (or weeks or months) later. In this blog post I’ll share the most important tmux commands.
I don’t want to make a tmux tutorial. There are several really good ones out there (see below). Instead, what you see below is a cheatsheet for quick reference:
Starting
- $ tmux
- $ tmux new-session -s basicCreate a session named basic
- $ tmux new -s basicCreate a session named basic
Sessions
- __PREFIX__ ddetach from our tmux session
- $ tmux list-sessionsor- tmux lsList sessions
- $ tmux attachAttach to our session
- $ tmux new -s second_session -dCreate a new session and detach it immediately
- $ tmux attach -t second_sessionAttach to named session
- $ tmux kill-session -t basicKill session named basic
- $ tmux new -s windows -n shellCreate a session name “windows” and name the first window “shell”
- __PREFIX__ sSelect sessions. Use the right arrow to select specific windows
- __PREFIX__ (Switch to previous session
- __PREFIX__ )Switch to next session
- __PREFIX__ $Rename session
Windows
- __PREFIX__ cCreate a new window
- __PREFIX__ ,Rename window
- __PREFIX__ nNext window
- __PREFIX__ pPrevious Window
- __PREFIX__ 4Go to window 4 (starting from 0)
- __PREFIX__ fFind window by name
- __PREFIX__ wDisplay a visual menu of window
Panes
- __PREFIX__ %Split window vertically
- __PREFIX__ "Split window horizontally
- __PREFIX__ oCycle through panes
- __PREFIX__ UP, DOWN, LEFT, RIGHTMove around the panes
- __PREFIX__ Cntrl-UP/DOWN/LEFT/RIGHTResize pane. Repeatable
- __PREFIX__ SPACECycle through default layouts
- __PREFIX__ xKill pane - useful if you can’t communicate with the process.
Command Mode
- __PREFIX__ :Go into command mode
- new-window -n processes "top"Create a new window named- processesrunning- top
Custom setups
- tmux attach -t developmentAttach to session named- development
- tmux split-window -v -t developmentSplit window in session named- development
- tmux new -s development -n machineOne -dCreate session named- development, name window- machineOneand detach immediately
- tmux send-keys -t development 'cd CocoaApps' C-m
- tmux split-window -v -t development
- tmux select-layout -t devlopment main-horizontal
- tmux send-keys -t development:0.1 'emacs' C-mOpen emacs in session- devlopment, screen 0, window 1
- tmux select-window -t development:1
Working with text
- __PREFIX__ [to enter copy mode,- ESCto exit. Emacs bindings to select and copy. Vi mode also possible.
Workflow
- __PREFIX__ ztoggle pane zoom
- : pipe-pane -o "log.txt"Toggle output piping to log.txt
- : pipe-pane -o "cat >> ~/#W.log" \; display "Toggled logging to ~/#W.log"Toggle output piping to log.txt