What's the equivalent of the "cls" command from Windows/DOS? [duplicate]

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?


Solution 1:

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)."

Solution 2:

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 a bash shell starts up.
  • The alias command defines the cls command to run the command quoted on the right-hand side.
  • printf command writes characters to the terminal. It accepts escape codes. The octal 033 is the character used to signal the beginning of a terminal control code. The control code c tells the terminal to clear itself.
  • So, with this modification to .bashrc. running cls sends the necessary data to the terminal to tell it to clear itself.