Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-21-2010, 07:01 PM   #1
LQ Newbie
Registered: Jan 2010
Posts: 4

Rep: Reputation: 1
Clear Screen Command for BASH Shell

I am unable to use clear or cls command on bash shell. I have recently installed Cygwin and am using that for practicing unix commands.

I see that I can use Ctrl + L to clear the screen. I created an alias in my .bashrc to do the same as
alias cls='^L'

This is how i defined other aliases e.g.
alias ll='ls -l'
alias la='ls -a'

and they work. Hence I assume cls will work too but this is what I get when I try to give cls on command prompt. Am i missing something? Is there a way to do this?

$ cls
bash: $'\f': command not found

Then someone suggested, You cannot alias keystrokes to commands or vice versa. You could just alias cls to an echo command: echo -en "\x0c"

And I added the following to .bashrc,

alias cls='echo -en "\x0c"'

Sourced the .bashrc file. No errors but cls still does not clear the screen.
Infact when I typed the echo -en "\x0c on command prompt as well, nothing happened.
What does this command do? Could you explain in detail as well.

Last edited by erora; 01-21-2010 at 07:02 PM.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-21-2010, 08:06 PM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
According to the info here, you'll need to install ncurses into your cygwin setup. There's some info in the other replies to the main question here that may be useful too.
2 members found this post helpful.
Old 01-21-2010, 09:35 PM   #3
LQ Newbie
Registered: Jan 2010
Posts: 4

Original Poster
Rep: Reputation: 1
Hi gilead,

Thanks for the suggestion. I installed the ncurses package through cygwin website and not clear command is working fine.
Thanks much!!
1 members found this post helpful.
Old 01-21-2010, 10:03 PM   #4
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
You can also try use this. Try to add add it in .bashrc.
function clear {
	local CLEAR=''

	type -p clear >/dev/null && \
		CLEAR=$(exec clear)
	[[ -z $CLEAR ]] && type -p tput >/dev/null && \
		CLEAR=$(exec tput clear)
	[[ -z $CLEAR ]] && \

	echo -en "$CLEAR"

	eval "function clear { echo -en '$CLEAR'; }"


clear, cls, screen

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to clear a std::string buff.clear()? lucky6969b Programming 3 03-17-2006 08:50 AM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 06:02 PM
how do you clear the ... dailyd Linux - Software 3 02-26-2004 05:03 PM
Clear this please lramos85 Fedora 3 02-06-2004 07:35 PM
still not clear garorag Linux - Newbie 2 09-18-2001 01:48 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration