What's the equivalent of the "cls" command from Windows/DOS?
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):
alias cls='printf "\033c"'
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.- The
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.- So, with this modification to
.bashrc
. runningcls
sends the necessary data to the terminal to tell it to clear itself.
In your current terminal window, just type the following:
printf "\033c"