Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
2  
Just open new tab and close current tab :D –  Tachyons Apr 3 '12 at 12:50
1  
by the way pressing ctrl+l is much fastern than typing clear and hitting enter –  Xn0vv3r Apr 3 '12 at 13:21
1  
It's bad habit. Try to dislearn it. You only need it rarely for some kind of ascii art, but deleting old information shouldn't be done routinely. Read The art of unix programming for further information. –  user unknown Apr 3 '12 at 13:58
1  
@userunknown Old information is deleted all the time. When you close a terminal window or log off a session in SSH or a virtual console. When an update replaces one version of installed software with another. When you run apt-get --purge .... When cookies/cache are cleared in a browser. To think clearing a terminal--a fundamental function of Unix-style terminals which works exactly the same way as in Windows but without the special command--is somehow inconsistent with good principles for operating *nix systems, seems like a failure of the imagination. –  Eliah Kagan Jan 11 '13 at 11:15
add comment

5 Answers

up vote 6 down vote accepted

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+X for Konsole (reset and clear scrollback).”

share|improve this answer
    
Why is it overkill? –  zpletan Apr 3 '12 at 15:07
1  
@zpletan Because it does a lot more than just clearing the scrollback buffer. Basically initializes the terminal as it was just opened. –  lgarzo Apr 3 '12 at 15:15
    
OK. I often thought that reset was kind of a melodramatic name for Linux's cls, but it makes sense now. In any case, it sounds like unless you do weird stuff with terminal customization, all it basically does is clear the screen/buffer/whatever, yes? –  zpletan Apr 3 '12 at 15:20
    
@zpletan I could just quote the manual, but to put it another way: there are situations when the terminal screen gets garbled and a simple clear would not do, but resetting it back to the default settings (and clearing the buffer along the way) will result again in a usable terminal. The first few paragraphs of man reset page describe the additional procedure. –  lgarzo Apr 3 '12 at 15:43
1  
@Mechanicalsnail Ah that. Well, that's more of a feature. There's Ctrl+Shift+X for Konsole (reset and clear scrollback). –  gertvdijk Feb 7 '13 at 8:36
show 3 more comments

cls 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 then reset is also a viable option as @lgarzo said.

share|improve this answer
add comment

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 history

share|improve this answer
add comment

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.
share|improve this answer
    
A related answer on SO. –  lgarzo Jan 16 '13 at 18:05
add comment

In your current terminal window, just type the following:

printf "\033c"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.