How do i clear tmux screen while tailing logs?

北城余情 提交于 2019-11-30 17:39:22

You can clear the current buffer using send-keys -R but keep in mind that the application running inside that buffer will not notice that the buffer contents have been wiped.

Reference

Ctrl-L is bound to a readline command. However, while you are running the command that tails your log, bash is not receiving keyboard input. You could suspend the tail with Ctrl-Z, clear the screen with Ctrl-L, and resume the tail with fg.

This is independent of tmux; I don't think tmux has anything like a clear-pane command, instead relying on the shell to handle that for you.

PhilT

In OSX (Terminal and I believe iTerm2), CMD+K clears and removes scrollback but I'm not sure this works when tailing or in tmux.

A couple of links may have your answer:

Also, @chepner suggested suspending the command and this gave me the idea to add it as a key binding (note: I've tested this on Linux but I don't have OSX. The first link seems to indicate clear-history may work):

bind-key -n C-l send-keys C-z \; send-keys " reset && fg > /dev/null" \; send-keys "Enter"

Add this to your ~/.tmux.conf then you can do CTRL+l and that will send the required keys and commands to the terminal to automate it.

reset && fg is prefixed with a space to exclude it from history.

The > /dev/null stops the original tail command being displayed but this might be useful so could be removed if you want to see it after clearing.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!