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 pipe-pane -o writes everything a pane prints to a file

Tmux
~/tips/tip-tmux-pipe-pane-log

tmux pipe-pane -o 'cat >>~/output.#I-#P'

Saves all output of a tmux pane to a log file, switched on and off with one key.

Scrollback is fine until the thing you need scrolled off the top an hour ago. When I want a record of what a pane printed, I’d rather have tmux write it to a file as it happens.

That is what pipe-pane does. It sends the output of a pane to a shell command of your choice, and cat appending to a file is the simplest one:

tmux pipe-pane -o 'cat >>~/output.#I-#P'

The #I and #P are replaced by the window and pane index, so every pane gets its own file. The -o flag only opens a pipe when none is open yet, which makes the command a toggle. Run tmux pipe-pane with no command at all and the current pipe is closed.

The tmux man page shows the toggle as a key binding, and that is how I’d use it. Put this in ~/.tmux.conf:

bind-key C-p pipe-pane -o 'cat >>~/output.#I-#P'

Now prefix plus Ctrl-p starts logging the current pane, and the same keys stop it. I find that useful for a long upgrade or a build I want to read back later without keeping the pane alive.

By default the pane’s output goes to the command (that is -O). There is also -I, which works the other way: whatever the command prints is typed into the pane. I’d leave that one alone unless you know why you want it.

Caveat: a pane can only have one pipe at a time, and starting a new one closes the old one. The file also gets the raw output, so colours and cursor movements end up in it as escape codes. less -R shows those files a lot better than a plain editor does.

Further reading: tmux manual: pipe-pane, On this site: tmux new -d runs a command that survives logout

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