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