LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

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

Rep: Reputation: 0
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.
 
Old 01-21-2010, 08:06 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
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.
 
1 members found this post helpful.
Old 01-21-2010, 09:35 PM   #3
erora
LQ Newbie
 
Registered: Jan 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Hi gilead,

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

Rep: Reputation: 233Reputation: 233Reputation: 233
You can also try use this. Try to add add it in .bashrc.
Code:
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 ]] && \
		CLEAR=$'\e[H\e[2J'

	echo -en "$CLEAR"

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


Reply

Tags
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/Novell 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


All times are GMT -5. The time now is 08:54 AM.

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