When I SSH to Linux servers I use the clear command a lot. This allows me to quickly reset the shell interface so there is no output so depending on if I have typed the incorrect command numerous times or the screen is filled without from something like the locate command I find it really useful to reset the interface so the screen is blank again without having to hit enter 50 times. On all of my Windows machines I have Cygwin installed to provide as much of a Linux feel as possible however I never have taken the time to figure out what installs the clear command so I could have the same luxury of clearing the windows Command Prompt or the Console2 application I use on a regular basis. Below I describe how to install clear on Windows using the Cygwin application.
Error Showing Clear Is Not Installed On Windows:
- 'clear' is not recognized as an internal or external command,
- operable program or batch file.
As you can see the above output is from a Command Prompt window which happens to be on my Windows 7 laptop. One other thing to consider is that I have added the Cygwin bin directory to my Windows users $PATH variable so I can launch Linux commands directly from any Command Prompt window or Console2 window.
Install Clear On Windows Via Cygwin:
The application that installs clear is called ncurses and this application also includes various other terminal handling utilities that you may find useful including not only clear but also including infocmp, tabs, tic, toe, tput, and tset. If you are curious what each of those commands does then search for the Linux man page for each of them on Google. This article will also assume basic knowledge of Cygwin but if you need more information you might read this article to find out how to add Cygwin to your path.
Launch Cygwin Setup And Search For ncurses:
Once you have located ncurses in the Cygwin setup interface put a check in the box as shown in the above example image to add it to the packages you are installing. Click the Next button to continue.
Install ncurses Dependencies Which Includes libncurses9:
Agree to install libncurses9 as shown in the above example image and then click the Next button to continue. Follow the prompts until the packages begin installing as shown below.
Install ncurses On Windows To Obtain clear Command:
Once the installation is completed. Close the Cygwin setup window. If you have any Command Prompt windows or Console2 type windows open they will need to be closes or the shell reset before the new commands will be available to you as shown in the below example image.
Example Of Using clear Command On Windows:
If you had previously filled the above Console window with various commands during your work session then you can clear the interface of all the garbage to start fresh by simply typing “clear” followed by enter and the end result would be a Console window that looks like the above example image.