Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
3  
Humm... my clear is part of the ncurses package, and doesn't clear the history, but only the terminal. –  Eric Smith Sep 19 '10 at 18:34

2 Answers 2

up vote 5 down vote accepted

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'

share|improve this answer

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.