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 clear-history wipes the scrollback of a pane

Tmux
~/tips/tip-tmux-clear-history

tmux clear-history

Deletes the scrollback of a tmux pane so copy mode starts fresh.

Before I start a build or a test run in a pane, I want the scrollback to begin with that run. Otherwise a search in copy mode happily finds an error from an hour ago. Ctrl-l gives you an empty screen, but scroll up and the old output is usually still waiting there. tmux has a command that throws it away.

tmux clear-history

Run inside a pane, it removes the history of that pane and frees the memory it used. The lines you see on screen stay; it is the part above them that goes. Clear the screen first and the pane is really empty:

clear && tmux clear-history

It also works on a pane you are not looking at, with -t. This clears pane 0 in window 1 of the session work, which is handy in a script that kicks off a long job there:

tmux clear-history -t work:1.0

If you do this often, a key binding in ~/.tmux.conf saves typing. After a reload, Ctrl-b K clears the history of the pane you are in:

bind K clear-history

There is no undo. The history is really gone and copy mode has nothing left to scroll through. If there is any chance you still need that output, save it to a file with capture-pane first, and only then clear. With a large history-limit that is a lot of lines to lose by one key.

Further reading: tmux manual page

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