Linux console clear all

Shell console clearing

Is there a way to clear up what is displayed on the shell console (in ubuntu linux) in just a single key or two? When I get flood of lines from grep and that exceeds the height of the window, I want to quickly scroll back to the position where I typed the command after the prompt. I can do so if I had opened a fresh terminal before I type the command, and just go to the initial position. But if keep using the same terminal window, I have to manually find the position. Ctrl + l is not an answer because it just scrolls, and the contents of the terminal remains. I cannot use less because the colored output of grep does not show up in color.

I am not familiar with DOS, but if that allows you to clear the window and have your scroll bar at the top position, then that is what I want.

cls in DOS clears the contents of the console and returns you to a blank screen with a fresh command prompt.

No, clear is the counterpart to cls . reset does more. Both will probably work, but based on your description, reset is overkill.

4 Answers 4

command, which is part of ncurses, and is located in the ncurses-bin package on Debian, will completely clear the console. Is that what you want?

Brief summary of reset from the man page:

reset sets cooked and echo modes, turns off cbreak and raw modes, turns on new-line translation and resets any unset special characters to their default values before doing terminal initialization the same way as tset.

Источник

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=

» width=»800″ height=»400″/>

Clear Terminal via clear Command

The fastest way to clear the terminal screen in Linux is with the clear command. In most terminal emulators, like GNU, running clear without any arguments creates a blank-slate screen:

clear command after terminal output

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:

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.

Читайте также:  Show ip route in linux

Источник

4 Useful Commands to Clear Linux Terminal Screen

Just like any other operating system, Linux also supports a rich Graphical User interface (GUI). In fact, it supports multiple graphical desktop environments such as – GNOME, KDE, Cinnamon, and the list goes on.

However, most Linux administrators and power users prefer to use the command line interface, because it allows us to automate repetitive tasks using the scripts.

One of the trivial downsides of this approach is that often times the terminal gets filled up with the command’s or script’s output. So, in some cases, cleaning up the terminal becomes necessary.

In this guide, we will discuss various methods that allow us to clean up the Linux terminal. After following this guide, Linux users can use one of the methods while working with Linux’s command line interface.

1. Clear Linux Terminal Using clear Command

The clear command is one of the most commonly used commands for clearing the Linux terminal. This command simply clears the terminal screen including its scroll-back buffers.

To understand the usage of the command, let’s execute a few commands in the terminal:

$ echo "Hello, World!" $ cat /etc/os-release

Now, to clean up the screen, just execute the clear command without any argument:

2. Clear Linux Terminal Screen Using CTRL+L Shortcut

In a similar way, we can use the ctrl+L shortcut to clear the terminal screen. However, this method doesn’t clean up the scroll-back buffers.

To illustrate this, first clear the terminal screen using the ctrl+L shortcut and then scroll up the screen using the mouse:

Clear Terminal Using CTRL+L Shortcut

In this example, we can see the previous output by scrolling up the terminal.

3. Reset (Clear) Linux Terminal Using reset Command

Additionally, we can also use the reset command to clear the terminal screen. Just like the clear command the reset command also clears the scroll-back buffers.

The reset command reinitializes the terminal hence it takes more time compared to the clear command.

4. Clear the Terminal Using the Escape Code

We can use the c escape code to clear the terminal. Let’s understand with a simple example.

In bash, we can use the \e escape sequence to represent the ESC character. So, to clear the terminal screen we can use the \ec string with the printf command as shown below:

In a similar way, we can use the \033 octal number to represent the ESC character. So to clear the terminal, we can use the \033c string with the printf command:

Читайте также:  Как удалить root пользователя linux

In addition to this, the hexadecimal number \x1B represents the ESC character. Hence we can use it to clear the screen:

In this guide, we discussed various methods for clearing the Linux terminal screen. Linux users can use one of the methods as per their choice.

Do you know of any other method for clearing the terminal in Linux? Let us know your views in the comments below.

Источник

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

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

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

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

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

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

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

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

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

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

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

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

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

Источник

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