46

I want to clearscreen from bash in a cygwin terminal. I have tried

cmd /c cls
echo -e "^V^L"
echo -e "\014"

None of these work - they all give a "linefeed". Pressing CTRL+L does work - but I want to call it from a Bash script.

Any ideas?

5
  • @Mat: This has the same effect as Ctrl+L, it only pushes the text up off the screen but doesn't clear it Commented Mar 24, 2013 at 13:08
  • 1
    tput mentioned below should be part of ncurses. Commented Mar 24, 2013 at 13:31
  • The Control-L character (which is formfeed, not linefeed) typically doesn't do anything when printed on vt100-like terminal emulators. Commented Sep 25, 2013 at 22:29
  • See also stackoverflow.com/q/11249070/1207769 Commented Feb 22, 2014 at 12:58
  • possible duplicate of Clear the Ubuntu bash screen for real Commented Feb 13, 2015 at 11:56

7 Answers 7

171

Or you could try ctrl-L :)

That should work in most emulated terminals as well.

Sign up to request clarification or add additional context in comments.

3 Comments

From the question: "Pressing CTRL+L does work - but I want to call it from a Bash script."
CTRL+L seems to only scroll away the old content, not remove it like ALT+F
Wow this answer sure is paying the bills! Sheesh, I wonder what "sudo !!" would get me.
67

There is two ways:

Using shortcuts

Alt+F8 to clear screen and Ctrl-L to skip page

Using Clear alias

  1. Go to: cygwin\home\USER\.bashrc
  2. Open .bashrc file and put this alias alias clear='printf "\033c"'.
  3. restart your cygwin terminal.
  4. to clear your screen use clear command.

1 Comment

From the question: "Pressing CTRL+L does work - but I want to call it from a Bash script."
35

If it's contained in your cygwin install (run Cygwin's setup and make sure you have the package called "ncurses"), try

tput clear

1 Comment

The real answer here is: install ncurses, then the "normal" clear command does work as Keith said.
26

I have this in my ~/.bashrc:

alias clear='printf "\033c"'

likewise, printf "\033c" clears the screen from within a bash script.

1 Comment

Clever solution. Just added it to my .bashrc
2

Alt+F8 to clear screen and Ctrl-L to skip page

Comments

1

Using shortcuts (for mitty console users)

Alt+F8 to clear screen and Ctrl-L to skip page

Using sh bash adding a command

If you use console2 or same consoles, you can add this sh code as without extension this location : ..\cygwin64\bin\

cls and /or clear (without extension)

#!/bin/sh
printf "\033c"

Then you can use cls and|or clear in cygwin command.

Comments

0

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...

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.