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 save-buffer – writes your last tmux copy to stdout

Tmux
~/tips/tip-tmux-save-buffer-stdout

tmux save-buffer - | wc -l

Writes the newest tmux copy buffer to a file or to standard output.

Text I copy in tmux copy mode lands in a tmux buffer, not in the system clipboard. The command line can reach that buffer, so a copied region becomes a file or a pipe.

save-buffer writes a paste buffer to a path. It takes the newest buffer unless you name one with -b. If the path is -, the buffer goes to stdout, so you can pipe it anywhere.

tmux save-buffer - | wc -l
tmux save-buffer ~/notes/copied.txt

With -a the buffer is appended to the file instead of overwriting it. That collects several selections in one file:

tmux save-buffer -a ~/notes/collected.txt

The reverse exists too. load-buffer reads a file into a buffer, or stdin when the path is -, and Ctrl-b ] pastes the most recently copied buffer:

echo 'ssh [email protected]' | tmux load-buffer -

The manual adds a -w flag to load-buffer that also sends the content to the clipboard of the terminal, if possible.

A buffer only exists after something was copied or loaded, so a fresh server has nothing to save. tmux list-buffers shows what is there. The system clipboard is a separate thing, and a tmux buffer ends up in it only if your setup copies it over.

Further reading: tmux manual

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

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