Delete last executed command in Linux terminal Delete last executed command in Linux terminal unix unix

Delete last executed command in Linux terminal


To do this you need to save the cursor position before the command and then restore the position after while clearing the rest of the screen.

Something like this should work:

$ hiderun() {    # Move cursor up one line.    tput cuu 1    # Save cursor position.    tput sc    # Execute the given command.    "$@"    # Restore the cursor position.    tput rc    # Clear to the end of the screen.    tput ed}$ iduid=0(root) gid=0(root) groups=0(root)$ uname -aLinux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux$ tput sc$ hiderun do something

This probably only works for a single-line prompt. Multiple line prompts probably need to change the argument to tput cuu.

Hm... having your prompt run tput sc as the first thing might mean this Just Works without needing to play any counting/etc. games but that would need some testing.