Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i clear tmux screen while tailing logs?

Tags:

iterm

tmux

I'm using tmux with iTerm2.

Clear screen using Ctrl-L works when i'm in bash, but does not work when i'm tailing server logs. How do i fix this?

like image 749
Sathish Avatar asked Feb 06 '13 14:02

Sathish


3 Answers

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

like image 176
jjungnickel Avatar answered Nov 11 '22 18:11

jjungnickel


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.

like image 45
chepner Avatar answered Nov 11 '22 18:11

chepner


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:

  • https://coderwall.com/p/rkstvg
  • https://apple.stackexchange.com/questions/31872/how-do-i-reset-the-scrollback-in-the-terminal-via-a-shell-command

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.

like image 5
PhilT Avatar answered Nov 11 '22 17:11

PhilT