5

For example, one of my bash aliases is this

alias p='clear;ls -lt;pwd;'

clear also clears the history which I don't want. I just want to clear the screen momentarily.

Ctrl+L however does exactly what I want. How can I use it in my alias?

1
  • 3
    Humm... my clear is part of the ncurses package, and doesn't clear the history, but only the terminal.
    – Eric Smith
    Commented Sep 19, 2010 at 18:34

2 Answers 2

6

If clear is clearing history and the terminal there must be a function, alias or script that is doing that. See what type -a clear tells you.

Another way to clear the terminal is to use tput clear which does exactly the same thing as what clear is supposed to do. You can also try doing it directly using the escape sequence (for xterm for example), but it may be different for different terminals (it should work for any that emulate xterm, such as gnome-terminal, PuTTY, etc.): printf '\e[H\e[2J'

2

What you've asked for in general is called executing a readline command from bash (the equivalent of zle -U $key_sequence or zle $widget $arguments[@] in zsh). As far as as I know, this is not possible in bash.

However, in this specific case, I don't observe any difference between running clear and typing Ctrl+L (readline command clear-screen).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .