brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmux capture-pane -p dumps the pane's text to stdout

Tmux
~/tips/tip-shell-tmux-capture-pane

tmux capture-pane -p -S - | grep -n 'error'

Prints everything in a tmux pane, scrollback included, so you can grep it.

A long build scrolled past and now the error is off the top of the screen. Scrolling back with the mouse is slow. Let tmux hand you the text.

capture-pane copies the contents of a pane. With -p the output goes to stdout instead of a tmux buffer, so you can pipe it. -S and -E pick the start and end line, and a negative number reaches into the scrollback; -S - starts at the very beginning of the history.

tmux capture-pane -p -S - | grep -n 'error'
tmux capture-pane -p -S -200 > last200.txt

Add -J to join wrapped lines and keep trailing spaces, so a long line is not cut in two at the edge of the window. Use -t to name another pane or session.

The caveat: you only get what tmux still has. The history limit defaults to 2000 lines, so older output is gone unless you raised history-limit in your config. A change there only applies to new panes. And colors are dropped unless you add -e, which is usually what you want for grepping.

Further reading: tmux(1) man page, On this site: tmux capture-pane -p dumps a pane's scrollback to a file, On this site: in tmux copy mode, / searches forward and ? searches backward

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link