LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Clear Screen Command for BASH Shell (https://www.linuxquestions.org/questions/linux-newbie-8/clear-screen-command-for-bash-shell-783873/)

erora 01-21-2010 06:01 PM

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.

gilead 01-21-2010 07:06 PM

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.

erora 01-21-2010 08:35 PM

Hi gilead,

Thanks for the suggestion. I installed the ncurses package through cygwin website and not clear command is working fine.
Thanks much!!

konsolebox 01-21-2010 09:03 PM

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'; }"
}



All times are GMT -5. The time now is 11:00 AM.