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 a pane's scrollback to a file

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

tmux capture-pane -p -S -3000 > build.log

Saves what a tmux pane shows, including its history, to a text file or the terminal.

A build failed and the error scrolled off. The text is still in the pane’s history.

tmux capture-pane -p -S -3000 > build.log

-p prints to standard output instead of tmux’s own buffer, and -S -3000 starts 3000 lines back in the history. Add -t work:1.0 to pick a pane that is not the current one.

The output of capture-pane comes from the pane’s history buffer, so the history limit decides how far back it can go. The -S flag sets the start line, with a negative number meaning that many lines back into the scrollback. Use -S - for the start of the whole history.

It also gives you a way to save the output of a job that was not logged. For a pane in another window, add the target: tmux capture-pane -p -t work:2.0 -S -. By default it leaves out colour codes, and -e keeps them if you want the colours too. Redirect to a file and you have a record you can search with grep.

You only get what is still inside the history limit. Raise history-limit before the job runs, because lines that already fell out of the history are gone.

Try it without risk: start a throwaway session with tmux new -s scratch, use the shortcut or command above there, look at what changes, and close the session again with tmux kill-session -t scratch. Nothing else on your machine is touched.

Further reading: tmux manual page (OpenBSD, official), tmux wiki: Getting Started (official), On this site: tmux capture-pane -p dumps the pane's text to stdout, On this site: set -g history-limit 50000 gives every pane a much longer scrollback

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