Bash – How to simulate keyboard shortcuts in a bash alias

aliasbashkeyboard shortcutslinux

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?

Best Answer

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'

Related Question