命令“clear”和“reset”有什么区别?
(整个问题都在标题中,但网站拒绝让我发表没有正文的帖子,因此重复)
答案1
man clear
和man reset
详细解释每个命令的作用。
clear
仅有的清除屏幕(如果可能的话,包括回滚缓冲区),并且它仅将执行此操作的终端序列输出到标准输出。其他设置不会被触及,例如,如果设置了背景颜色,clear
将以该颜色填充终端:
tput setab 2; clear; echo test
reset
完全重置终端:它将各种模式恢复到预期值,重置窗口大小,重置延迟和选项卡扩展,输出终端的“重置”或“初始化”序列,并刷新输出。它尝试各种输入和输出来确定如何与您的终端对话,而不是盲目地使用标准输出;这确保它会对您的终端产生影响。它还等待给终端时间来重置。因此
tput setab 2; reset; echo test
将始终导致具有默认设置的清除终端(在大多数默认设置中为黑底白字)。
如果您尝试两者,您会发现这clear
是瞬时的,而reset
需要一秒钟多一点(因为它明确地休眠了一秒钟,希望这足以用于重置正在使用的任何终端)。
答案2
NAME
clear - clear the terminal screen
SYNOPSIS
clear [-Ttype] [-V] [-x]
DESCRIPTION
clear clears your screen if this is possible, including its scrollback
buffer (if the extended “E3” capability is defined). clear looks in
the environment for the terminal type given by the environment variable
TERM, and then in the terminfo database to determine how to clear the
screen.
clear writes to the standard output. You can redirect the standard
output to a file (which prevents clear from actually clearing the
screen), and later cat the file to the screen, clearing it at that
point.
NAME
tset, reset - terminal initialization
SYNOPSIS
tset [-IQVcqrsw] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]
reset [-IQVcqrsw] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]
reset - reinitialization
When invoked as reset, tset sets the terminal modes to “sane” values:
• sets cooked and echo modes,
• turns off cbreak and raw modes,
• turns on newline translation and
• resets any unset special characters to their default values
before doing the terminal initialization described above. Also, rather
than using the terminal initialization strings, it uses the terminal
reset strings.
The reset command is useful after a program dies leaving a terminal in
an abnormal state.
第一个清除屏幕,包括回滚缓冲区。最重要的是,第二个重置输入和输出。reset
也有点慢。