I used to use cmd back in windows, and the command line I used a lot, was cls
. It's kind of like the clear
command used in Linux, but it cleans the screen permanently.
If you use the clear
command, it just scroll down, so that you don't see the command you where working on.
I like both a lot, but my question is, how do i get a cls
like command, that clears the screen, and can't browse up, to see the command you where working on?
You can use
reset
. This resets the whole terminal, so that may be a bit overkill though.Note on Konsole:
@Mechanical snail noticed "in Konsole 4.8.5, the old text is still there if you scroll up". @gertvdijk explained that it is "a feature. There's Ctrl+Shift+K for Konsole (reset and clear scrollback)."
Add this line to
~/.bashrc
(i.e., the file called.bashrc
, located in your home folder -- you can see it in Nautilus by pressing Ctrl+H):Now the
cls
command will clear the screen like in Windows. It will put you back to the top of a Terminal window, with no text shown above it. (It will not delete the shell's command history.)This works because:
.bashrc
runs every time abash
shell starts up.alias
command defines thecls
command to run the command quoted on the right-hand side.printf
command writes characters to the terminal. It accepts escape codes. The octal033
is the character used to signal the beginning of a terminal control code. The control codec
tells the terminal to clear itself..bashrc
. runningcls
sends the necessary data to the terminal to tell it to clear itself.In your current terminal window, just type the following:
If the aim is to avoid only casual rediscovery of command history,
reset
may be a viable choice.However, bear in mind that by default, the shell logs your command history to a file as well - this is also eminently discoverable. If you want to prevent other persons from browsing your command history, you should also clean that out.
history -c
# clear your historycls
works by clearing the buffer, which is fixed 25 or 50 lines in case of DOS and Windows, respectively. You can achieve something like this by writing so many lines in the buffer that it overflows (2000 is a typical value), but thenreset
is also a viable option as @lgarzo said.