今天,我只是在试验Linux shell。这是我所做的。1.我将clear的输出写到文件中:
$clear > clear.txt
2。现在,我在外壳上有一些内容(非空)。然后我尝试cat
clear.txt
$cat clear.txt
令我惊讶的是,整个屏幕都被清除了。我能解释一下为什么吗?如果这是真的,为什么我们不能对所有命令都这样做?
不是一个真正的解释,但它应该如何工作:
http://man7.org/linux/man-pages/man1/clear.1.html
@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.
这是clear命令的直观表示。编辑文本文件将产生:
^[[3J^[[H^[[2J
clear
的工作原理非常简单,只需传输一系列由您的终端解释的控制代码即可。响应接收到这些控制代码,由终端(或终端仿真器,控制台界面或您碰巧使用的任何东西)处理真正清除屏幕的魔力。