Как сбросить терминал linux

Clear a terminal screen for real [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Using the clear command on the terminal only fools the user into thinking the screen has been cleared. you can still see output from the previous commands when you scroll using the mouse. This makes life difficult when you are drowning in a tsunami of text. Various solutions (escape code etc.) which can be found on the Internet are only variations of what the clear command already does. So how do you clear the contents of a terminal in Linux for real?

I’d categorize this as «software tools commonly used by programmers» (mentioned in the FAQ as valid).

What you’re really asking is «How can I clear the terminal’s scroll-back buffer?» which is independent of the shell (Bash) or Ubuntu.

@spiderplant0 probably because AskUbuntu is the right place for this — at this time. Didn’t exist when this was asked, so it got closed as off topic, even though that isn’t the case.

That’s a more general question, affecting not only Ubuntu or bash, as @Dennis noted. I’d change the topic «Clear the Ubuntu bash screen for real» —> «Clear a terminal screen for real»

There are many different terminal types with which you can run Bash (the term «bash terminal» is meaningless). «Clearing» isn’t applicable to all of them — sometimes, the nearest approximation is to tear the paper and bin/shred/burn/destroy the bit you don’t want.

12 Answers 12

Use the following command to do a clear screen instead of merely adding new lines .

yes that’s a ‘printf’ on the bash prompt.

You will probably want to define an alias though.

Explanation

So this becomes c which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.

Edit

Here are a few other ways of doing it.

printf "\ec" #\e is ESC in bash echo -en "\ec" #thanks @Jonathon Reinhart. # -e Enable interpretation of of backslash escapes # -n Do not output a new line 

The above does not work on the KDE console (called Konsole) but there is hope! Use the following sequence of commands to clear the screen and the scroll-back buffer.

Or perhaps use the following alias on KDE.

alias cls='clear && echo -en "\e[3J"' 

I got the scroll-back clearing command from here.

This is actually terminal specific. «\033c» is ESC c which is the VT-XXX escape sequence for «Full Reset (RIS)». Almost all terminals people actually use these days are VT compatible, but if you ever find yourself using a weird terminal, this might not work. @vpit3833’s answer is more likely to work assuming TERM is set correctly.

Читайте также:  Linux массовое изменение прав

printf is a Bash builtin (it’s true that it’s also a separate binary, but builtins have precedence and most modern shells have printf ).

@SDX2000 OK . I know you specified Ubuntu, and I assumed that these would behave similar on all «modern» terminal emulators. I initially tested on my MAC’s terminal and it did not reset there, but it did reset on my Centos Linux.

$0.02 a few years later, but i’m a student at CU. Asked my operating systems professor and he said this was an example of ANSI escape sequence: en.wikipedia.org/wiki/ANSI_escape_code This is an example of in-band signalling.

The solution for KDE is a solution for xterm and terminals that support xterm’s escape sequences. The official list of xterm escape sequences is at invisible-island.net/xterm/ctlseqs/ctlseqs.html. (If you want to learn more about terminal escape sequences, see ANSI escape sequence).

Try reset . It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.

Thanks! But it clears every thing including the prompt. See my answer for a solution which doesn’t do this.

@SDX2000 Both clear the prompt, and then the shell generates a new one. The one disadvantage to reset is that it seems to be a bit slower (probably because it does more than just emit ESC c) but it’s more portable.

@SDX2000 reset is also handy for those cases where your terminal gets badly mangled because you killed something (or catted a binary file) and it left your term in a mangled state. Ever get into a state where your prompt shows up but not your typing, and when you hit enter the new prompt shows up next to the previous prompt rather than below it? reset fixes that. That’s actually all I ever use it for. I’ve never had a need/desire to clear my scroll-back buffer.

Источник

Как очистить терминал Linux

Если вы хотите делать снимки экрана терминала Linux или вам хочется чтобы окно терминала перед выполнением команды с очень длинным выводом было пустым, вам понадобиться возможность очистки терминала.

Существует несколько способов это сделать. Можно воспользоваться горячей клавишей, или выполнить несколько команд. Можно очистить только текущий экран или полностью весь вывод. В сегодняшней статье мы расскажем как выполняется очистка терминала в Linux.

Как очистить терминал в Linux

Самый простой способ очистить терминал — воспользоваться сочетанием клавиш Ctrl + L. После нажатия этих клавиш весь уже существующий вывод переместиться вверх, так, что текущее окно терминала будет пустым:

Тем не менее вся история вывода не будет удалена, вы сможете легко получить к ней доступ просто пролистав немного вверх:

Но если вы не будете пытаться листать историю, окно будет чистым. Если этого вам мало, вы можете воспользоваться командой clear. Она полностью очищает вывод и к предыдущему выводу вы уже вернуться не сможете:

Для того чтобы утилита clear не очищала полностью историю вывода, доступную при прокрутке, а работала аналогично сочетанию клавиш Ctrl+L используйте опцию -x:

Но и у этой команды есть одна проблема. Если вы по ошибке вывели содержимое двоичного файла, ваш эмулятор может быть сломан. Все вводимые вами символы могут превратиться в кракозябры, а приглашение ввода вовсе перестанет работать. Такое происходит потому что в двоичных файлах могут случайно встретиться какие-нибудь управляющие последовательности, ломающие работу терминала.

Читайте также:  Linux professional institute 101

В такой ситуации команда clear не поможет, здесь нужна команда reset:

Она сбрасывает терминал полностью, не только предыдущий вывод, но и любые настройки, заданные с помощью управляющих последовательностей. После её выполнения вы получите чистый терминал.

Как видите, очистить терминал Linux очень просто. А какие способы знаете вы? Напишите в комментариях!

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

How to Clear Terminal in Linux

The clear command is the go-to tool for clearing the terminal screen in Linux. Despite its effectiveness, clear does not reinitialize the terminal, which is sometimes necessary. Some alternative methods provide users with that option as well.

Read this tutorial to learn how to clear the terminal in Linux using different methods.

How to Clear Terminal in Linux <Clear Screen in Linux data-lazy-src=

The command deletes everything, including the scrollback buffer. To keep the scrollback buffer, use clear with the -x argument:

clear -x terminal output before

The clear -x command clears the terminal, but previous output is still available. Scroll up or use the PgUp button:

clear -x terminal output after

However, in some terminal emulators, clear without arguments doesn’t delete previous output but shifts it upwards (same as clear -x in GNU). In that case, accessing earlier output is possible with the PgUp key.

Additionally, the clear command does not reset the terminal. The shell state remains the same as before.

Clear Terminal via reset Command

Unlike clear , the reset command reinitializes the terminal and restores settings to default. The reinitialization process covers tab extensions, turns off echo and raw modes, and turns on newline translation.

The command resets a terminal that is in an abnormal state and reinitializes the command line:

reset terminal output before

Executing reset takes a few moments to complete while clear shows effect instantly.

Clear Terminal via Ctrl+L / Ctrl+Shift+K Shortcut

Keyboard shortcuts also work for clearing the terminal, depending on the terminal emulator.

In GNOME, the Ctrl + l shortcut has the same effect as clear -x. The shortcut clears the terminal while leaving the scrollback buffer:

ctrl + l and new command terminal output

Typing in a new command, like whoami, is done on a clear screen. Still, users can access command output history with PgUp or by scrolling up:

ctrl + l terminal output

An alternative in some terminal emulators is Ctrl + Shift + K . The command provides the same output as Ctrl + L .

Clear Terminal via alias Command

Alternative methods for clearing the terminal are also more complicated. For instance, the \033 is the ASCII escape character used to start terminal control sequences. When followed by c , the command clears the terminal.

printf 33c terminal output

The command clears the terminal screen, including the scrollback buffer. To avoid typing numbers, create an alias for the command. For instance, set x as an alias for printf «\033c» with:

Читайте также:  Настройка общей папки в virtualbox astra linux

alias terminal output

Once the alias is created, running x results in a clear terminal screen.

Now you know how to clear the terminal screen using a few different methods. Next, check out the ultimate guide of all Linux commands everyone should know.

Источник

How to Clear Terminal Screen in Ubuntu and Other Linux Distributions [Beginner’s Tip]

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 Terminal Screen 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?

Источник

Оцените статью
Adblock
detector