The “clear” Command in Linux [3 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The clear command in Linux is a very easy-to-use command that is used for clearing the terminal screen. In this article, you will learn the syntax, options, and practical applications of the clear command in Linux.

A. Description

The clear command clears your terminal screen if possible. It also scrolls down the terminal screen to clear it. It observes the terminal type in the environment given by the environment variable TERM, and then in the terminfo database to decide how the screen can be cleared. Standard output is also written by the clear command in Linux.

B. Syntax

The clear command in Linux has a simple syntax. The syntax of the command is as follows:

clear [-OPTION]

Note: In the syntax above, OPTION is enclosed by a square bracket representing that one option can be used in a single command.

C. Options

The clear command has a few options. I have listed them here. However, if you want to gain more knowledge about the options of the clear command you can look for the man page for the clear command.

man clear

Useful Options

  • -T, Indicates the type of terminal
  • -V, Reports the version of ncurses
  • -x, Scrolls down the terminal, does not remove history

Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be careful while using them.

Practical Examples of the “clear” Command in Linux

The clear command is used to clear the terminal screen. It is a very simple command. Here you will get to know some examples of the clear command in Linux.

Example 1: Clear the Terminal Using the “clear” Command in Linux

To clear the terminal screen, I am using the clear command. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Write some random commands.

➌  To clear the terminal, type the following command in the command prompt:

clear

❹Now, press the ENTER button.

Output >

As you can see, the clear command cleared everything on the terminal screen.

Before executing the “clear” command >Typing the clear command in linux TerminalAfter executing the “clear” command >
Clears the Terminal



Example 2: Scroll Down the Terminal Using the “clear” Command in Linux

To clear the terminal screen without removing history, I am using the clear command with the option -x. It actually scrolls down the terminal screen. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Write some random commands.

➌ To clear the terminal without removing history, type the following command in the command prompt:

clear -x

❹ Now, press the ENTER button.

Output >

In the following images, the output displays the clear command scrolled down the terminal screen.

Before executing the “clear -x” command >Typing clear-x to scroll Down the TerminalAfter executing the “clear -x” command >
Scrolls Down the Terminal

Note: You can also press CTRL + L instead of clear -x. This is one of the shortcuts used in Linux.

Example 3: Reset the Terminal

To re-initialize the terminal, you can also use the reset command in Linux.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To re-initialize the terminal, type the following command in the command prompt:

reset

➌ Now, press the ENTER button.

Output >

In the images below, the output displays the reset command reinitialized the terminal screen.

Before executing the “reset” command >typing reset command instead of the clear command in linuxAfter executing the “reset” command >
Resets the Terminal

Conclusion

As you have seen in this section, the clear command has less usage in Linux. Here you’ve got to know the syntax, options, and practical application of this command. You have also seen a glimpse of the reset command in Linux. If you want to become an expert in Linux, go through the details of the command and its practical applications.


Related Articles

Rate this post
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

Leave a Comment