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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.):
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