来自 bash 的 cygwin clearscreen
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15598245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cygwin clearscreen from bash
提问by ManInMoon
I want to clearscreen from bash in a cygwin terminal. I have tried
我想在 cygwin 终端中从 bash 清除屏幕。我试过了
cmd /c cls
echo -e "^V^L"
echo -e "4"
None of these work - they all give a "linefeed". Pressing CTRL+L does work - but I want to call it from a Bash script.
这些都不起作用-它们都给出了“换行”。按 CTRL+L 确实有效 - 但我想从 Bash 脚本中调用它。
Any ideas?
有任何想法吗?
采纳答案by mikyra
If it's contained in your cygwin install (run Cygwin's setup and make sure you have the package called "ncurses"), try
如果它包含在您的 cygwin 安装中(运行 Cygwin 的安装程序并确保您有名为“ncurses”的包),请尝试
tput clear
回答by gNU.be
Or you could try ctrl-L :)
或者你可以试试 ctrl-L :)
That should work in most emulated terminals as well.
这也应该适用于大多数仿真终端。
回答by Abudayah
There is two ways:
有两种方式:
Using shortcuts
使用快捷键
Alt+F8
to clear screen and Ctrl-L
to skip page
Alt+F8
清除屏幕和Ctrl-L
跳过页面
Using Clear
alias
使用Clear
别名
- Go to:
cygwin\home\USER\.bashrc
- Open
.bashrc
file and put this aliasalias clear='printf "\033c"'
. - restart your cygwin terminal.
- to clear your screen use
clear
command.
- 去:
cygwin\home\USER\.bashrc
- 打开
.bashrc
文件并放置这个别名alias clear='printf "\033c"'
。 - 重新启动您的 cygwin 终端。
- 清除屏幕使用
clear
命令。
回答by vertikalist
I have this in my ~/.bashrc:
我的 ~/.bashrc 中有这个:
alias clear='printf "3c"'
likewise, printf "\033c" clears the screen from within a bash script.
同样, printf "\033c" 从 bash 脚本中清除屏幕。
回答by Ravi Macha
Alt+F8 to clear screen and Ctrl-L to skip page
Alt+F8 清屏,Ctrl-L 跳过页面
回答by bdllhtlgn
Using shortcuts (for mitty
console users)
使用快捷方式(对于mitty
控制台用户)
Alt+F8
to clear screen and Ctrl-L
to skip page
Alt+F8
清除屏幕和Ctrl-L
跳过页面
Using sh bash
adding a command
使用sh bash
添加命令
If you use console2
or same consoles, you can add this sh code
as without extension this location : ..\cygwin64\bin\
如果您使用console2
或 相同的控制台,则可以sh code
将此位置添加为不带扩展名:..\cygwin64\bin\
cls
and /or clear
(without extension)
cls
和/或clear
(不带扩展名)
#!/bin/sh
printf "3c"
Then you can use cls
and|or clear
in cygwin command.
然后你可以在 cygwin 命令中使用cls
and|or clear
。
回答by user102958
I was trying to do something similar and upon researching I found the above answers, I tried to follow some of the above solutions, I added the line to .bashrc, but it did not accept the function, I tweaked around and found out another solution...it basically executes the ' printf "\33c" but instead of tweaking the .bash.rc file, you simply go to the directory - /cygwin/bin , Write the following command :- printf "\033c" And save it with the filename "cls" , in the bin directory, ensure that there is NO EXTENSION to the file, thus it will have the type "file" ..save it,open the shell and the command will run...
我试图做一些类似的事情,经过研究,我找到了上述答案,我尝试遵循上述一些解决方案,我将该行添加到 .bashrc,但它不接受该功能,我进行了调整并找到了另一个解决方案...它基本上执行' printf "\33c" 但不是调整 .bash.rc 文件,您只需转到目录 - /cygwin/bin ,编写以下命令:- printf "\033c" 并保存它文件名为 "cls" ,在 bin 目录中,确保文件没有扩展名,因此它将具有 "file" 类型..保存它,打开外壳,命令将运行......
I found this method by playing around with msys and cygwin, I have both on my windows PC and turns out msys supports the "cls" command, I found a file with the same name in it's bin directory and copied it to the cygwin's bin folder and edited the file with the printf function and this worked like a charm...hope this helps.
我通过玩弄 msys 和 cygwin 找到了这个方法,我的 Windows PC 上都有,结果 msys 支持“cls”命令,我在它的 bin 目录中找到了一个同名的文件并将其复制到 cygwin 的 bin 文件夹并使用 printf 函数编辑文件,这就像一个魅力......希望这会有所帮助。