当前位置: 首页 > 工具软件 > ScrollBack > 使用案例 >

linux 清理控制台,清除Linux虛擬控制台終端的scrollback緩沖區。

毛缪文
2023-12-01

I'd like to clear the scrollback buffer on Linux console VTs programmatically. i.e. not just clear the current visible screen, but the entire scrollback buffer, too. I.e. everything that after a clear screen would still be visible with Alt-PgUp should be gone too. Anybody got an idea how to achieve that in nice code?

我想以編程方式清除Linux控制台VTs上的scrollback緩沖區。也就是說,不僅要清除當前可見的屏幕,還要清除整個scrollback緩沖區。也就是說,在一個清晰的屏幕之后,用Alt-PgUp仍然可以看到的東西也應該消失了。有人知道如何用漂亮的代碼實現嗎?

3 个解决方案

#1

6

I don't think this is in mainline yet, but linux-next has a patch to support a new console escape sequence that clears the screen and the scrollback buffer: CSI 3 J

我不認為這是主線,但是linux-next有一個補丁來支持一個新的控制台轉接程序,它可以清除屏幕和scrollback緩沖區:CSI 3 J。

For something that works without having to upgrade your kernel, you can use:

對於那些無需升級內核的工作,您可以使用:

chvt 42; chvt ; echo -en "\e[1;1H\e[2J"

Alternatively:

另外:

echo -e "\e[12;42]"; sleep .01; echo -en "\e[12;]\e[1;1H\e[2J"

You can get the current tty number with:

你可以得到當前的tty號碼:

$( ls -l /proc/self/fd | sed -ne 's/.*tty//p' )

#2

1

Keep in mind that other tools (over ssh for example) will have differing implementations of the "scrollback buffer". I highly doubt that you can clean the putty buffer by code in your machine. Also see https://superuser.com/questions/122911/bash-reset-and-clear-commands

請記住,其他工具(例如,在ssh上)將有不同的“回滾緩沖區”實現。我非常懷疑您可以通過代碼在您的機器上清除putty緩沖區。也看到https://superuser.com/questions/122911/bash-reset-and-clear-commands

#3

0

This clears the screen, but not the scrollback.

這將清除屏幕,但不會清除回滾。

echo -e '\0033\0143' #depends on the terminal emulator you are using, tested on gnome terminal

echo -e '\0033\0143' #依賴於您正在使用的終端模擬器,在gnome終端上進行測試。

從https://superuser.com/questions/122911/bash-reset-and-clear-commands

 类似资料: