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-sessionsortmux 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 modenew-window -n processes "top"Create a new window namedprocessesrunningtop
Custom setups
tmux attach -t developmentAttach to session nameddevelopmenttmux split-window -v -t developmentSplit window in session nameddevelopmenttmux new -s development -n machineOne -dCreate session nameddevelopment, name windowmachineOneand detach immediatelytmux send-keys -t development 'cd CocoaApps' C-mtmux split-window -v -t developmenttmux select-layout -t devlopment main-horizontaltmux send-keys -t development:0.1 'emacs' C-mOpen emacs in sessiondevlopment, screen 0, window 1tmux 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