
「clear」コマンドと「reset」コマンドの違いは何ですか?
(質問全体がタイトルにあり、サイトで本文なしで投稿することを拒否して重複が発生しました。)
答え1
man clear
そしてman reset
各コマンドが実行する操作について詳しく説明します。
clear
ただ画面を消去し(可能であればスクロールバックバッファを含む)、それを実行する端末シーケンスを標準出力に印刷します。他の設定は触れません。たとえば、背景色が設定されている場合、clear
端末はその色で塗りつぶされます。
tput setab 2; clear; echo test
reset
端末を完全にリセットします。さまざまなモードを期待値に復元し、ウィンドウサイズをリセットし、遅延とタブ拡張をリセットし、端末の「リセット」または「初期化」の順序、出力を更新します。標準出力を盲目的に使用するのではなく、さまざまな入力と出力を試して端末と通信する方法を決定します。これは端末に影響を与える可能性があります。また、端末がリセットされるのを待ちます。だから
tput setab 2; reset; echo test
常にデフォルト設定で明確な端末が生成されます(ほとんどのデフォルト設定では、黒の背景に白いテキスト)。
両方を試してみると、これはclear
即座であり、reset
1秒が少し時間がかかることがわかります。 (明示的に1秒間スリープ状態にあるので、使用中の端末をリセットするのに十分であることを願っています。)
答え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.
最初はスクロールバックバッファを含む画面を消去します。最も重要なことは、2番目の項目が入力と出力をリセットすることです。reset
また、少し遅いです。