- How to Clear Terminal Screen in Ubuntu and Other Linux Distributions [Beginner’s Tip]
- Clear Linux terminal with clear command
- Other ways to clear terminal screen in Linux
- Thread: How do I clear screen in terminal
- How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Re: How do I clear screen in terminal
- Clear! (clear your terminal screen)
- JasKinasis
- KarlLinux
- NeoBeum
- Abhijit Mohanty
- Abhijit Mohanty
- atanere
- TCRatius
- wizardfromoz
- TCRatius
- JasKinasis
How to Clear Terminal Screen in Ubuntu and Other Linux Distributions [Beginner’s Tip]
Last updated October 27, 2020 By Abhishek Prakash 11 Comments
When you are working in the terminal, often you’ll find that your terminal screen is filled up with too many commands and their outputs.
You may want to clear the terminal to declutter the screen and focus on the next task you are going to perform. Clearing the Linux terminal screen helps a lot, trust me.
Clear Linux terminal with clear command
So, how do you clear terminal in Linux? The simplest and the most common way is to use the clear command:
You need no option with the clear command. It’s that simple but there are some additional things you need to know about it.
The clear command and other methods of clearing screen may depend on the terminal emulator you are using. Terminal emulator is the terminal application that you use for accessing the Linux shell (command line).
If you use clear command on Ubuntu with GNOME Terminal, it will clear the screen and you won’t be able to see what else you had on the screen previously.
In many other terminal emulators or Putty, it may just clear the screen for one page. If you scroll with mouse or PageUp and PageDown keys, you can still access the old screen outputs.
Frankly, it depends on your need. If you suddenly realize that you need to refer to the output of a previously run command, perhaps having that option available will be helpful.
Other ways to clear terminal screen in Linux
Clear command is not the only way to clear the terminal screen.
You can use Ctrl+L keyboard shortcut in Linux to clear the screen. It works in most terminal emulators.
If you use Ctrl+L and clear command in GNOME terminal (default in Ubuntu), you’ll notice the difference between their impact. Ctrl+L moves the screen one page down giving the illusion of a clean screen but you can still access the command output history by scrolling up.
Some other terminal emulators have this keyboard shortcut set at Ctrl+Shift+K.
You can also use reset command for clearing the terminal screen. Actually, this command performs a complete terminal re-initialization. It could take a bit longer than clear command, though.
There are a couple of other complicated ways to clear the screen when you want to clear the screen completely. But since the command is a bit complicated, it’s better to use it as alias in Linux:
You can add this alias to your bash profile so that it is available as command.
I know this was a pretty basic topic and most Linux users probably already knew it but it doesn’t harm in covering the elementary topics for the new Linux users. Isn’t it?
Got some secretive tip on clearing terminal screen? Why not share it with us?
Like what you read? Please share it with others.
Источник
Thread: How do I clear screen in terminal
Thread Tools
Display
How do I clear screen in terminal
I’m using Ubuntu 13.10 on a VMware virtual machine installed on my Mac for about three days now.
In terminal on the Mac there is command-K which clears the screen; I really like it.
I’m using the Terminal application that came with Ubuntu.
From the GUI menu I see «Reset.» But when I go to the keyboard shortcuts part of the Terminal app, it says «Disabled» next to «Reset.»
How can I enable a keyboard shortcut to clear or reset the screen?
Re: How do I clear screen in terminal
Hi To clear screen in terminal try shortcut
Re: How do I clear screen in terminal
In rare occasions (especially when catting binaries to the console by mistake), the console gets stuck in a mode where things don’t print properly. In those instances, I use reset which seems more thorough in restoring settings.
Last edited by The Cog; November 19th, 2013 at 05:39 PM .
Re: How do I clear screen in terminal
Are those documented somewhere?
Re: How do I clear screen in terminal
It looks like both clear and ctrl-L are described in the manual page for bash, but you almost have to know they are there to find them. If you look hard you can find it in there.
If I recall correctly, ctrl-l was ‘form feed’ and used to advance the teletype to the next fold in the paper. It got carried over to clear the screen when we moved off of paper.
Re: How do I clear screen in terminal
Wow, so easy. Thanks.
Are those documented somewhere?
ctrl r is awesome
Re: How do I clear screen in terminal
Are those documented somewhere?
The Linux Documentation Project (tldp.org) is a handy site to find tutorials and other things Linux. Check it out.
Spider Jerusalem, Transmetropolitan #4
Re: How do I clear screen in terminal
If you have garbage output all over you screen (just weird looking symbols/non-english chars) ‘reset’ will also work like a charm.
Re: How do I clear screen in terminal
The Bash man page is excruciating. Does anyone actually understand it? Don’t get me wrong. I very much appreciate all of the contributions that the FOSS community has made to the Linux-sphere, but that has to be the densest, most obscure and jargon-laden piece of arcanna I’ve ever tried to decipher. In my opinion, it stands as a shining example of how not to write a man page, which, after all, is at least partly meant to be a help document. What most distros need is a Bash cheater sheet for the rest of us. Perhaps just eight or ten screens deep and filled with stuff like + and + with one- or two-line summaries of use and function.
Ahh. Feel better now that I’ve got that off my chest.
A system upgrade is a heart, lung and brain transplant. !!BACKUP FIRST!!
Источник
Clear! (clear your terminal screen)
Administrator
When you’re typing a lot in a terminal and want to clear the screen quickly, you can do so easily a couple different ways.
The one most people know about:
Yeah, simply type ‘clear’.
The one you’ll use a lot more:
(hit the ctrl key, then a lowercase L)
It doesn’t make everything go away, you can actually see everything if you scroll up, but its very handy and I can’t tell you how many times I use it each day.
(really — I can’t tell you, because when you type ‘clear’ you’ll see it in your history, but if you use ctrl-l, it doesn’t make it into history)
JasKinasis
Well-Known Member
Rob, this might be a little advanced for a beginners tutorial, but I feel it is worth mentioning:
The Ctrl-l shortcut only works as a shortcut for the «clear» command if you have readline
I use the following line in my .bashrc, which puts readline into vi input mode:
In the vi input mode, the Ctrl+l keybind is only available when in ‘command’ mode. So you have to hit and then Ctrl-l. Which is not really very helpful. It would also be handy to have it available in ‘insert’ mode too.
The good news is — you can easily add a keybind for Ctrl-l for ‘insert’ mode by adding the following line to your .bashrc:
Either method works. I edited .bashrc because it involved less typing and because I pretty much use bash exclusively.
But if you tend to switch between using different shells.
e.g. Bash, zsh, ksh, csh etc.
Then putting the settings into .inputrc will apply those settings to ANY shell that uses readline. In other words — no matter what shell you are using, your keybinds/settings for readline will always be the same.
Whereas .bashrc only applies to bash.
There are many different bits of functionality and options available in readline. So if there are any key-binds/shortcuts to functionality that you feel you are missing in either vi or emacs mode, you can easily set up a new keyboard shortcut — as I have done for clear-screen in the vi insert mode.
The man page for readline contains a lot of information about the functionality/options that are available.
KarlLinux
New Member
NeoBeum
New Member
Abhijit Mohanty
New Member
I tried both, however, I could scroll up and view the entire commands. [just started linux]
Administrator
I tried both, however, I could scroll up and view the entire commands. [just started linux]
Abhijit Mohanty
New Member
atanere
Well-Known Member
If you want to delete the entire command history, see if this works:
TCRatius
Member
Rob, this might be a little advanced for a beginners tutorial, but I feel it is worth mentioning:
The Ctrl-l shortcut only works as a shortcut for the «clear» command if you have readline
I use the following line in my .bashrc, which puts readline into vi input mode:
In the vi input mode, the Ctrl+l keybind is only available when in ‘command’ mode. So you have to hit and then Ctrl-l. Which is not really very helpful. It would also be handy to have it available in ‘insert’ mode too.
The good news is — you can easily add a keybind for Ctrl-l for ‘insert’ mode by adding the following line to your .bashrc:
Either method works. I edited .bashrc because it involved less typing and because I pretty much use bash exclusively.
But if you tend to switch between using different shells.
e.g. Bash, zsh, ksh, csh etc.
Then putting the settings into .inputrc will apply those settings to ANY shell that uses readline. In other words — no matter what shell you are using, your keybinds/settings for readline will always be the same.
Whereas .bashrc only applies to bash.
There are many different bits of functionality and options available in readline. So if there are any key-binds/shortcuts to functionality that you feel you are missing in either vi or emacs mode, you can easily set up a new keyboard shortcut — as I have done for clear-screen in the vi insert mode.
The man page for readline contains a lot of information about the functionality/options that are available.
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
wizardfromoz
Administrator
Hi @TCRatius and a belated welcome to the site.
A search from our home page under «text editor» just on the words yields close to 200 results, but narrowing it down to in the title — less than 2 pages.
@Rob’s poll here https://www.linux.org/threads/poll-favorite-text-editor.6/ invites comment, I am going there tomorrow I hope
TCRatius
Member
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Administrator
Hey there TCRatius,
Welcome to the forums — sure, we’d love it if you shared a link to us from another forum.
JasKinasis
Well-Known Member
As the saying goes:
«Necessity is the mother of all invention»
I’ve been using Linux for many years — and I’ve always learnt things as and when I’ve needed to. And I’m continuing to learn. I’m always learning new things.
Any time I have a problem, or want to know how to be able to do something new — I’ve always looked to the documentation.
Now, I know telling people to RTFM is a bit of a cliche, but seriously:
RTFM FTW!
There is a LOT of information in the man and info pages. Reading through it can be time well spent. And if you don’t want to read the entire manual — you could always just search for parts of the manual that you are interested in using the search command.
e.g.
In the man-page viewer, you can press / and enter a regex to search for specific text.
If the documentation is incomplete, or unclear — I will look to the internet for answers. And 99% of the time I manage to find an existing solution without having to post a question myself.
Sometimes it takes a bit of time to find exactly what I need, so a bit of patience and persistence is required. But to me — it’s worth it!
To clear up any misunderstanding that you may have:
My original post has nothing to do with the systems default text editor, or anybody’s preferred editor — it is purely about the default shortcut keys available in Bash via GNU readline — which depends on which input-style readline is set-up to use (emacs or vi).
GNU readline is a command-line utility which is used by various command-line tools to get input from users. This includes shells like bash.
So when you are typing commands in bash — whether you know it or not, you are using readline. And whilst editing commands in bash you can use emacs or vi style keyboard shortcuts. Again, the default for readline is emacs, so whether you knew it or not — in Bash, you’ve had emacs style keyboard shortcuts available to you the whole time. Even if you haven’t been using them — they are there.
When you are using nano (or whatever your favourite command line text editor is) you are using nanos keyboard shortcuts. But when typing commands in Bash, depending on how readline is set up, you will either be using emacs style keyboard shortcuts, or vi-style shortcuts.
In my original post, I was pointing out that Robs suggestion to use «ctrl + l» to clear the screen in the terminal only works «out of the box» if your shell has readline set to its default ’emacs’ input mode.
Personally, I’m a vim user — so I quite like using the vi input mode for readline.
If readline is set to use the vi input mode, you have to press — to switch from vi-insert mode to vi-command mode and then press «ctrl +l» to clear the screen. And it’s a little clunky, having to press and then «ctrl+l».
So for the benefit of other users who use readlines vi option — I demonstrated how to set up a custom keybind for readlines vi-insert mode, which would allow «ctrl+l» to be used to clear the screen whilst editing a command (without having to press first).
WRT .bashrc:
You can edit .bashrc with ANY text editor you like. But the edits specified in my post will only set up a new key-bind for readlines vi-input mode.
Readline doesn’t have a nano input mode. It only has emacs or vim input modes. But if you really wanted to, you could create custom keybinds for any of readlines emacs or vi input modes, that will mimic keybinds/functionality from nano or any other editor.
But, many of nano’s keyboard shortcuts are similar to the emacs shortcuts anyway.
e.g.
ctrl+n = next line,
ctrl+p = previous line,
ctrl+f = next character,
ctrl+b = previous character
etc.
So for a nano user, the emacs input method for readline would probably meet most, if not all of your needs anyway!
I hope I explained all of that clearly enough.
If you have any further questions, fire away!
For reference:
Here is the list of the default keyboard shortcuts for Bash — including the emacs-style «cursor movement» and «editing» keybinds:
https://gist.github.com/michaelcoyote/745d8a6cf293c4bf7e31
Switching to the vi mode would change all of the keybinds in the «cursor movement» and «editing» sections to be more vi-like. The other commands (history, process control etc) are mostly the same.
Источник