201

I installed Cygwin, choosing a fairly minimal set of packages.

In a terminal, I tried to do 'clear' to clear the terminal, but I get

bash: clear: command not found

How do I get this to work?

braX
  • 11,506
  • 5
  • 20
  • 33
  • 103
    You can also type control-L. – Keith Thompson Jun 28 '12 at 17:05
  • 1
    Yes, but (for me) that does not work in `set -o vi` mode; it _does_ work in `set -o emacs` mode though. Thanks. – MarnixKlooster ReinstateMonica Jun 28 '12 at 18:04
  • 1
    In `set -o vi` mode, you can type escape followed by control-L (then `i` to get back to insert mode). (Personally, I like vi as an editor, but not as an interactive shell mode.) – Keith Thompson Jun 28 '12 at 18:37
  • 4
    press ctrl+L to clear – KOTIOS Jul 05 '13 at 06:10
  • 2
    Note that the `ncurses` package (as stated in the accepted answer) also includes other useful terminal-related commands such as `tput`, so it may be worth installing depending on your needs. – Donald Burr Sep 09 '13 at 00:08
  • When I hit ctrl+L it does not clear the terminal, it just scrolls my current line to the top. The terminal appears clear but if I scroll up using the side bar I can see it is not clear at all. This is very irritatint when debugging programs and wanting to clear the past data between compilations etc. Would like to be able to actually clear the terminal as I can in Linux – Sam Redway Sep 17 '14 at 11:11
  • @MarnixKlooster not that it's optimal but even in vi mode you can exit input mode to normal via or similar. – thynctank Mar 17 '15 at 18:33

10 Answers10

243

Install the Cygwin package ncurses; it is in the Utils category.

Zombo
  • 1
  • 62
  • 391
  • 407
127

This should do:

alias clear='printf "\033c"'
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Krishna Murthy
  • 1,377
  • 1
  • 8
  • 4
  • 2
    Great answer. In older versions of Cygwin, `cmd /c cls` used to work as described at http://stackoverflow.com/q/15598245/1207769. But that solution stopped working, whereas this `printf` still works as of this writing. – ctrueden Feb 22 '14 at 13:04
  • 1
    Excellent - still works as of sept 2014. Just for added clarity note you can add this to your ./bashrc file (just copy and past the line) which you will find under /home/[username] and you will make this permanent. – Sam Redway Sep 17 '14 at 11:33
  • This also works a charm for [Gow](https://github.com/bmatzelle/gow) bash, but msysgit has its own clear program in the bin directory – icc97 May 06 '15 at 10:11
  • 1
    This is the best answer to clear scrollback as well as the current screen. Ncurses does not clear scrollback for me. – blockloop Jan 07 '16 at 18:52
  • Great answer... You can use this even on production servers where you're not allowed to install packages (i know... Cygwin on production Windows servers.. not my choice xd). You just have to add it to your `~/.bashrc` file and `source` it and it's done... Nice job pointing that out – LukeSavefrogs Feb 07 '20 at 15:40
37

just use this shortcut: Alt+F8 and Ctrl-L to skip page

Abudayah
  • 3,816
  • 7
  • 40
  • 60
  • 4
    This is not what the user asked for, sometimes clearing a the screen is really useful for quickly making sure the output you get is from where you think it is from. – DrCord Sep 10 '13 at 22:07
  • 1
    But not an answer at all to the question, if you put every slightly related piece of useful information on every stack overflow post then it would be monstrous. – DrCord Sep 23 '13 at 16:29
  • 4
    A Google search for "cygwin clear screen" got me here, this answer was correct for me. You can be however strict you want about answers, scope, limits and whatnot - but as far as I'm concerned, this solved it for me and gets an up vote as truly "helpful". – Bing Mar 06 '14 at 09:59
  • 1
    And so the battle raged: the purists and the anti-purists shelling from opposite sides of the philosophical divide. If a combatant was killed, he was tossed into the chasm, and as he fell both sides covered their ears to avoid hearing the screams of the Paradoxes. – Stabledog Dec 09 '14 at 13:44
15

Use cygcheck command to check what package it is in (adding .exe to your cmd string, in this example: clear.exe)

> cygcheck -p 'clear.exe'
Found 4 matches for clear.exe
ncurses-debuginfo-5.9-20150307-1 - ncurses-debuginfo: Debug info for ncurses (installed binaries and support files)
ncurses-debuginfo-5.9-20150404-1 - ncurses-debuginfo: Debug info for ncurses (installed binaries and support files)
ncurses-5.9-20150307-1 - ncurses: Terminal display utilities (installed binaries and support files)
ncurses-5.9-20150404-1 - ncurses: Terminal display utilities (installed binaries and support files)

and you know you have to install ncurses package using cygwin installer.

Kossak
  • 1,273
  • 1
  • 16
  • 31
13

It's nice to have the clear.exe program for bash script files, so:

Windows Cygwin detail for clear.exe program command.

  1. Download Cygwin setupx86.exe or whatever it's call at http://cygwin.com/

  2. Run it and download from internet. *If you have a proxy connection, you may need to use Internet Explorer settings or set up custom proxy.

  3. Choose all default settings, and finish the installation.

  4. Run the installer a second time and again download from internet, but this time you will go into Utils, when it comes to the tree of files to customize your installation.

  5. Expand Utils and get down to the ncurses" files. There, you will click on the skip item, to the left of the ncurses utils (there are a few).

  6. After changing from skip to whatever version of ncurses you want to install, continue the installation, and finish.

  7. Run the installer again and this time you will expand Lib aka libraries.

  8. Find the terminfo library installer, and again change skip to the newest version, then continue and complete the installation.

NOTE You might end up having to log out of Windows and log back in, or just reboot before the new programs take effect. This is due to the possibility of Cygwin background session.

NOTE You also must do the three separate installations.

Chris McFarland
  • 6,059
  • 5
  • 43
  • 63
Jared French
  • 131
  • 1
  • 3
  • @Chris: I am asking this just for the sake of clarity. Why is terminfo database library required here ? The clear command worked fine for me. I read about terminfo (as provided [link](http://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html)) but want to know is there anything specific it does here ? – Starney Jun 16 '15 at 18:21
12

I tried in my system: It works:

Just use: cntrl+l

Hope this help!

Anshu Kumar
  • 633
  • 7
  • 12
11

Right click > Reset... (Alt + F8) worked for me... (on Cygwin-x86-2.830)

SxOne
  • 143
  • 1
  • 8
7

Open Windows Explorer then navigate to:

[Cygwin Installation Directory]\home\[User]\

e.g.: C:\cygwin\home\wreckseal

then open the file .bashrc with Notepad++.

Move your cursor at the end of the last line and hit Enter key, then add the text below.

alias cls='echo -e "\033c"'

or the text below:

alias cls='printf "\033c"'

Restart cygwin, type cls. Done!

Note that there's no scrollbar after sending the cls command. I prefer the printf version than the echo version. Try it yourself!

wreckseal
  • 73
  • 1
  • 5
7

Search for "/clear.exe$" => Install "ncurses"

TLDR: Package search uses regular expressions. So searching for regex "/clear.exe$" will give you the best match. This leads to the ncurses package.


General approach to such problems:
Search on the Cygwin-package search page with the full executable name.

Now the package search can be done in several ways:

And all of these 3 matches are now from several versions of the ncurses package. So in order to get clear.exe you need to install ncurses.

(Pro tip: Right-click the search-field and create a customized search engine. I have set this to the shortcut cp for "cygwin package" in both Firefox and Chrome.)

StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
2

I just came across this project and so far, I think it's awesome

https://github.com/transcode-open/apt-cyg

after installing it, you can run

apt-cyg install ncurses

I personally prefer installing libraries using this tool over the Cygwin tool b/c the Cygwin versions all have .exe appended to them, and can be cumbersome when copying and pasting Linux commands (off of SO, for instance).

rasjani
  • 7,372
  • 4
  • 22
  • 35
Bradley Bossard
  • 2,439
  • 2
  • 23
  • 30