LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06:01 PM   #1
erora
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 06:02 PM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-21-2010, 07:06 PM   #2
gilead
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, 08:35 PM   #3
erora
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, 09:03 PM   #4
konsolebox
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.
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



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 07:50 AM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM
how do you clear the ... dailyd Linux - Software 3 02-26-2004 04:03 PM
Clear this please lramos85 Fedora 3 02-06-2004 06:35 PM
still not clear garorag Linux - Newbie 2 09-18-2001 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration