brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Ctrl-l clears the shell screen and keeps the line you are typing

Shell
~/tips/tip-shell-ctrl-l-clear-keep-line

docker compose logs --tail 50 web # now at the top of a clean screen

Clear the terminal without losing the half-typed command.

When the screen is full of old output and you want a clean view, typing clear means first throwing away what you were writing. Ctrl-l does not.

Press it at any moment, also halfway through a command:

$ docker compose logs --tail 50 web   # half typed, screen full of junk
# press Ctrl-l
$ docker compose logs --tail 50 web   # now at the top of a clean screen

The screen clears, the prompt moves to the top, and your line and cursor stay exactly where they were. You can keep typing.

It also helps after a program printed something on top of your prompt, like a background job finishing. The line gets redrawn cleanly.

The scrollback is a different story. In most terminals Ctrl-l scrolls the old output up instead of deleting it, so you can still scroll back. That is usually what I’d want, but it is not a way to hide something from the person next to you. In bash 5.1 and newer, Alt-Ctrl-l clears the scrollback as well, if the terminal supports it.

Further reading: Bash manual: Commands For Moving

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link